cmake/c++11-test-variadic_templates-N2555.cpp

Fri, 23 Aug 2013 01:20:09 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 23 Aug 2013 01:20:09 +0300
changeset 478
c7f8989c995f
parent 473
2a84149fe642
permissions
-rw-r--r--

bit of a clarification

473
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 int Accumulate()
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 {
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 return 0;
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 }
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 template<typename T, typename... Ts>
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 int Accumulate(T v, Ts... vs)
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 {
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 return v + Accumulate(vs...);
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 }
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 template<int... Is>
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 int CountElements()
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 {
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 return sizeof...(Is);
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 }
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 int main()
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 {
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 int acc = Accumulate(1, 2, 3, 4, -5);
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 int count = CountElements<1,2,3,4,5>();
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 return ((acc == 5) && (count == 5)) ? 0 : 1;
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 }

mercurial