Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- template <typename T>
- T add(T first) {
- return first;
- }
- template <typename T, typename ... Args>
- T add(T car, Args... cdr) {
- return car + add(cdr...);
- }
- template <int ... Args>
- int total() {
- return add(Args...);
- }
- int main(int argc, char** argv)
- {
- using std::cout;
- using std::endl;
- int s1 =
- total<0, 1, 2, 3>();
- std::cout << "s1 = " << s1 << std::endl;
- // The following does not compile:
- #if 0
- int s2 =
- total<std::make_integer_sequence<int, 4>>();
- std::cout << "s2 = " << s2 << std::endl;
- static_assert(s1 == s2, "no match");
- #endif
- // This should work:
- //
- {
- cout << typeid(std::make_integer_sequence<int, 4>()).name() << endl;;
- cout << std::make_integer_sequence<int, 4>().size << endl;;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement