-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTemplate.cc
executable file
·137 lines (113 loc) · 3.4 KB
/
Template.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*BINFMTCXX: -DSTANDALONE
*/
// Copyright (C) 2021 Nathan Paul Simons ([email protected])
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#if defined STANDALONE
// For boost::type_index.
# include <boost/type_index.hpp>
// For copy().
# include <algorithm>
// For std::cout and std::endl.
# include <iostream>
// For std::ostream_iterator<>.
# include <iterator>
// For std::runtime_error() and std::exception.
# include <stdexcept>
// For std::map<>.
# include <map>
// For EXIT_SUCCESS and EXIT_FAILURE.
# include <cstdlib>
void authenticateUser();
template<typename Container,
typename Index>
decltype(auto)
authAndAccess(Container&& container_,
Index index_)
{
authenticateUser();
return std::forward<Container>(container_)[index_];
}
template <typename Type>
void function(const Type& parameter_)
{
using std::cout;
using std::endl;
using boost::typeindex::type_id_with_cvr;
cout << "T = "
<< type_id_with_cvr<Type>().pretty_name()
<< endl;
cout << "parameter_ = "
<< type_id_with_cvr<decltype(parameter_)>().pretty_name()
<< endl;
}
class Widget
{
};
/** Main entry to program.
*
* Checks arguments, prints them out, prints "Hello, world!", prints a
* newline, then exits.
*
* This may seem like a contrived "hello, world", but it is meant as a
* template for quickly prototyping ideas (see the binfmtc package
* which allows scripting with C, C++, Assembly, Java, FORTRAN and
* Pascal). It is also designed to compile with as few errors and
* warnings as possible, even with all warnings enabled. Lastly, it
* shows how to access commandline arguments, program using STL, and
* do some basic sanity checking.
*
* \param argc Number of arguments.
* \param argv Arguments.
* \return EXIT_SUCCESS.
* \exception std::runtime_error Non-conformant arguments.
*/
int main(int argc,
char* argv[])
{
try
{
using std::cout;
using std::endl;
using std::ostream_iterator;
using std::runtime_error;
if (argc < 1 ||
argv[0] == nullptr)
throw runtime_error("arguments error");
copy(argv,
argv + argc,
ostream_iterator<char*>(cout, "\n"));
cout << "Hello, world!" << endl;
std::map<int, int> m;
for (const auto &i : { 0, 1, 2, 3, 4 })
{
m[i] = rand();
}
for (const auto& p : m)
{
cout << p.second << endl;
}
}
catch(const std::exception& ex) // try
{
std::cerr << "Exception raised: " << ex.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
} // int main(int argc, char* argv[])
#endif // #if defined STANDALONE
// Local Variables:
// mode: C++
// End:
// vi: fileformat=unix expandtab shiftwidth=2 tabstop=2