/*============================================================================= Copyright (c) 2001-2011 Joel de Guzman Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main() { using namespace boost::fusion; using namespace boost; { vector0<> vec; (void) vec; std::cout << "(): " << sizeof(vec) << std::endl; std::cout << (boost::is_empty >::value ? "is empty" : "is not empty") << std::endl; } { typedef vector1 type; type vec; BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 1); BOOST_TEST(at_c<0>(vec) == 0); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); // prove that it is mutable at_c<0>(vec) = 987; BOOST_TEST(at_c<0>(vec) == 987); } { typedef vector1 type; type vec(123); BOOST_TEST(at_c<0>(vec) == 123); std::cout << "(int): " << sizeof(vec) << std::endl; } { // testing const vector vector1 const vec(999); BOOST_TEST(at_c<0>(vec) == 999); #ifdef FUSION_TEST_COMPILE_FAIL at_c<0>(vec) = 321; #endif } { vector1 t1(123L); // try conversion from long to int vector1 t2(t1); // try copy (void)t2; } { typedef vector2 type; type vec; BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 2); BOOST_TEST(at_c<0>(vec) == 0); BOOST_TEST(at_c<1>(vec) == char()); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); } { typedef vector2 type; type vec(123, 'x'); BOOST_TEST(at_c<0>(vec) == 123); BOOST_TEST(at_c<1>(vec) == 'x'); std::cout << "(int, char): " << sizeof(vec) << std::endl; } { vector2 t1(123, 456); vector2 t2(t1); (void)t2; } { typedef vector3 type; type vec; BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); BOOST_TEST(at_c<0>(vec) == 0); BOOST_TEST(at_c<1>(vec) == char()); BOOST_TEST(at_c<2>(vec) == double()); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); } { typedef vector3 type; type vec(123, 'x', 123.456); BOOST_TEST(at_c<0>(vec) == 123); BOOST_TEST(at_c<1>(vec) == 'x'); BOOST_TEST(at_c<2>(vec) >= 123.455 && at_c<2>(vec) <= 123.457); std::cout << "(int, char, double): " << sizeof(vec) << std::endl; } { typedef vector4 type; type vec(123, 'x', 123.456, true); std::cout << "(int, char, double, bool): " << sizeof(vec) << std::endl; } { typedef vector4 type; type vec(123, 'x', true, 123.456); std::cout << "(int, char, bool, double): " << sizeof(vec) << std::endl; } { typedef vector7 type; type vec(false, 'x', 3, 4, 5, 6.f, 7.0); BOOST_TEST(at_c<0>(vec) == false); BOOST_TEST(at_c<1>(vec) == 'x'); BOOST_TEST(at_c<2>(vec) == 3); BOOST_TEST(at_c<3>(vec) == 4); BOOST_TEST(at_c<4>(vec) == 5); BOOST_TEST(at_c<5>(vec) >= 5.9 && at_c<5>(vec) <= 6.1); BOOST_TEST(at_c<6>(vec) >= 6.9 && at_c<6>(vec) <= 7.1); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); BOOST_STATIC_ASSERT((boost::is_same::type>::value)); std::cout << "(bool, char, short, int, long, float, double): " << sizeof(vec) << std::endl; } { typedef vector10 type; type vec; // compile check only std::cout << "vector10 of int: " << sizeof(vec) << std::endl; } { typedef vector20< int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int> type; type vec; // compile check only std::cout << "vector20 of int: " << sizeof(vec) << std::endl; } { typedef vector30< int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int> type; type vec; // compile check only std::cout << "vector30 of int: " << sizeof(vec) << std::endl; } { typedef vector40< int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int> type; type vec; // compile check only std::cout << "vector40 of int: " << sizeof(vec) << std::endl; } { typedef vector50< int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int , int, int, int, int, int, int, int, int, int, int> type; type vec; // compile check only std::cout << "vector50 of int: " << sizeof(vec) << std::endl; } { // testing copy and assign from a view vector0<> empty; fusion::vector2 v(fusion::push_back(fusion::push_back(empty, 123), 456)); BOOST_TEST(at_c<0>(v) == 123); BOOST_TEST(at_c<1>(v) == 456); v = fusion::push_back(fusion::push_back(empty, 123), 456); // test assign BOOST_TEST(at_c<0>(v) == 123); BOOST_TEST(at_c<1>(v) == 456); } { // testing copy and assign from a vector_c mpl::vector_c vec_c; fusion::vector2 v(vec_c); BOOST_TEST(at_c<0>(v) == 123); BOOST_TEST(at_c<1>(v) == 456); v = mpl::vector_c(); // test assign BOOST_TEST(at_c<0>(v) == 123); BOOST_TEST(at_c<1>(v) == 456); } return boost::report_errors(); }