#define USE_MPL 1 #define SEQUENCE list //#define SEQUENCE vector //#define AT slow_at #define AT fast_at #if USE_MPL #include #include #include #include #include #include #include using namespace boost; using namespace mpl; template struct make_list { typedef typename push_front::type, int_ >::type type; }; template <> struct make_list<0> { typedef SEQUENCE<> type; }; int const test_length = 100; typedef make_list::type lista; template struct test { static int const value = at >::type::value + test::value; }; template struct test { static int const value = 0; }; int main() { assert(( test<0, test_length>::value == test_length*(test_length+1)/2)); } #else #include struct nil; template struct list { typedef H head; typedef T tail; }; template struct slow_at { typedef typename slow_at::type type; }; template struct slow_at { typedef typename L::head type; }; template struct drop { typedef typename drop::type::tail type; }; template struct drop <0, L> { typedef L type; }; template struct fast_at { typedef typename drop::type::head type; }; template struct node { static int const value = N; }; template struct make_list { typedef list, typename make_list::type> type; }; template <> struct make_list<0> { typedef nil type; }; int const test_length = 100; typedef make_list::type lista; template struct test { static int const value = AT::type::value + test::value; }; template struct test { static int const value = 0; }; int main() { assert(( test<0, test_length>::value == test_length*(test_length+1)/2)); } #endif