Gobelijn API documentation
- generated for commit a0cbea7
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Friends
Macros
Pages
adder.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the gobelijn software.
3
* Gobelijn is free software: you can redistribute it and/or modify it
4
* under the terms of the GNU General Public License as published by the
5
* Free Software Foundation, either version 3 of the License, or any later
6
* version. Gobelijn is distributed in the hope that it will be useful, but
7
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8
* or FITNESS FOR A PARTICULAR PURPOSE.
9
* See the GNU General Public License for details. You should have received
10
* a copy of the GNU General Public License along with the software. If not,
11
* see <http://www.gnu.org/licenses/>.
12
*
13
* Copyright 2016, Jan Broeckhove, CoMP/UA.
14
*/
19
#if defined(__GNUC__)
21
#define COMP_MISC_FUNCTION_NAME __PRETTY_FUNCTION__
22
#else
23
#define COMP_MISC_FUNCTION_NAME __FUNCTION__
24
#endif
25
26
#include <iostream>
27
28
using namespace
std;
29
30
// Ends recursion of the varyadic template.
31
template
<
typename
T>
32
T
Adder
(T v)
33
{
34
cout <<
"\n\t ----> \n\t "
<<
COMP_MISC_FUNCTION_NAME
<<
"\n\t <----- \n"
<< endl;
35
return
v;
36
}
37
38
// Varyadic template.
39
template
<
typename
T,
typename
... Args>
40
T
Adder
(T first, Args... args)
41
{
42
cout <<
"\n\t ----> \n\t "
<<
COMP_MISC_FUNCTION_NAME
<<
"\n\t <----- \n"
<< endl;
43
return
first +
Adder
(args...);
44
}
45
46
// Demo.
47
int
main
()
48
{
49
cout <<
Adder
(1, 2, 3, 4) << endl;
50
cout <<
Adder
(2, 1.3, 1U, 2.0e2) << endl;
51
cout <<
Adder
(
string
(
"haha"
),
string
(
"hihi"
),
string
(
"hoho"
)) << endl;
52
}
COMP_MISC_FUNCTION_NAME
#define COMP_MISC_FUNCTION_NAME
Macro to take advantage of PRETTY_FUNCTION over plain FUNCTION with gcc.
Definition:
adder.cpp:23
Adder
T Adder(T v)
Definition:
adder.cpp:32
main
int main()
Definition:
adder.cpp:47
main
cpp
template_demo
adder.cpp
Generated on Fri Feb 1 2019 09:33:32 for Gobelijn API documentation by
1.8.6