1 void adance(std::list<int>::iterator& iter, int d) 2 { 3 if(typeid(std::iterator_traits<std::list<int>::iterator>::iterator_catagory) 4 ]== typeid(std::random_access_iterator_tag)){ 5 iter += d; 6 }else{ 7 if(d >= 0) while(d--)iter++; 8 else while(d++) iter--; 9 } 10 }
1 template<unsigned n> 2 struct Factorial{ 3 enum{value = n * Factorial<n - 1>::value}; 4 }; 5 template<> 6 struct Factorial<0>{ 7 enum{value = 1}; 8 };
简单的说一下:tarits技法就是一种模板元编程,起可以将本来处于运行期的事拉到编译期来做,增加了运行效率。 看以非模板元编程的例子,就是前面的那个例子:
原文:http://www.cnblogs.com/-wang-cheng/p/4889837.html