c++模板元编程模板的模板参数

代码如下:

/* [email protected] www.gaimo.net 02.15.2009 */ //dev c++ #include <cstdlib> #include <iostream> //#include <vector> //#include <string> //#include <algorithm> using namespace std; template<int N, template<int> class F> struct accumulate { enum {RET = accumulate<N-1,F>::RET + F<N>::RET}; }; template<template<int> class F> struct accumulate<0,F> { enum { RET = F<0>::RET }; }; template<int n> struct square { enum { RET = n*n }; }; int main(int argc, char *argv[]) { cout << accumulate<5,square>::RET << endl; system("PAUSE"); return EXIT_SUCCESS; }

你可能感兴趣的:(Algorithm,编程,C++,c,System,Class)