| 1 | // Copyright 2017 Peter Dimov. |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | |
| 4 | #include <boost/tuple/tuple.hpp> |
| 5 | #include <boost/core/lightweight_test.hpp> |
| 6 | #include <boost/config.hpp> |
| 7 | #include <boost/config/pragma_message.hpp> |
| 8 | |
| 9 | #if defined(BOOST_NO_CXX11_HDR_TUPLE) |
| 10 | |
| 11 | BOOST_PRAGMA_MESSAGE("Skipping std::tuple_size tests for lack of <tuple>" ) |
| 12 | int main() {} |
| 13 | |
| 14 | #else |
| 15 | |
| 16 | #include <tuple> |
| 17 | |
| 18 | template<class Tp> void test( std::size_t x ) |
| 19 | { |
| 20 | BOOST_TEST_EQ( std::tuple_size< Tp >::value, x ); |
| 21 | BOOST_TEST_EQ( std::tuple_size< typename Tp::inherited >::value, x ); |
| 22 | } |
| 23 | |
| 24 | struct V |
| 25 | { |
| 26 | }; |
| 27 | |
| 28 | int main() |
| 29 | { |
| 30 | test< boost::tuple<> >( x: 0 ); |
| 31 | test< boost::tuple<V> >( x: 1 ); |
| 32 | test< boost::tuple<V, V> >( x: 2 ); |
| 33 | test< boost::tuple<V, V, V> >( x: 3 ); |
| 34 | test< boost::tuple<V, V, V, V> >( x: 4 ); |
| 35 | test< boost::tuple<V, V, V, V, V> >( x: 5 ); |
| 36 | test< boost::tuple<V, V, V, V, V, V> >( x: 6 ); |
| 37 | test< boost::tuple<V, V, V, V, V, V, V> >( x: 7 ); |
| 38 | test< boost::tuple<V, V, V, V, V, V, V, V> >( x: 8 ); |
| 39 | test< boost::tuple<V, V, V, V, V, V, V, V, V> >( x: 9 ); |
| 40 | test< boost::tuple<V, V, V, V, V, V, V, V, V, V> >( x: 10 ); |
| 41 | |
| 42 | #if !defined(BOOST_NO_CXX11_DECLTYPE) |
| 43 | |
| 44 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple())>::value, 0 ); |
| 45 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1))>::value, 1 ); |
| 46 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2))>::value, 2 ); |
| 47 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3))>::value, 3 ); |
| 48 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4))>::value, 4 ); |
| 49 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4, 5))>::value, 5 ); |
| 50 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4, 5, 6))>::value, 6 ); |
| 51 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4, 5, 6, 7))>::value, 7 ); |
| 52 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4, 5, 6, 7, 8))>::value, 8 ); |
| 53 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4, 5, 6, 7, 8, 9))>::value, 9 ); |
| 54 | BOOST_TEST_EQ( std::tuple_size<decltype(boost::make_tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))>::value, 10 ); |
| 55 | |
| 56 | #endif |
| 57 | |
| 58 | return boost::report_errors(); |
| 59 | } |
| 60 | |
| 61 | #endif |
| 62 | |