Advertisement
pcwizz

ewe templates

Oct 19th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template<int head, int... tail>
  6. struct total_struct {
  7.     static int const value = head + total_struct<tail...>::value;
  8. };
  9.  
  10. template<int head>
  11. struct total_struct<head> {
  12.     static int const value = head;
  13. };
  14.  
  15. template<int... list>
  16. int total()
  17. {
  18.     return total_struct<list...>::value;
  19. }
  20. int main ()
  21. {
  22.     cout << total<1,2,3,4,5,6,7,8,9>() << endl;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement