#include #include #include #include #include "test.hpp" struct tuple_for_each_f { template constexpr auto operator()(Sequence&& s, F && f) const FIT_RETURNS ( fit::unpack(fit::by(fit::forward(f)))(fit::forward(s)), fit::forward(f) ); }; FIT_STATIC_FUNCTION(tuple_for_each) = tuple_for_each_f{}; FIT_TEST_CASE() { std::tuple tp{ 1, 2, 3 }; { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } } FIT_TEST_CASE() { std::tuple const tp{ 1, 2, 3 }; { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } } // #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 8 // #else FIT_TEST_CASE() { std::tuple, std::unique_ptr, std::unique_ptr> tp{ std::unique_ptr(new int(1)), std::unique_ptr(new int(2)), std::unique_ptr(new int(3)) }; int s = 0; tuple_for_each( std::move(tp), [&]( std::unique_ptr p ){ s = s * 10 + *p; } ); FIT_TEST_CHECK( s == 123 ); } FIT_TEST_CASE() { auto tp = fit::pack(1, 2, 3); { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } } FIT_TEST_CASE() { const auto tp = fit::pack(1, 2, 3); { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } } // #endif FIT_TEST_CASE() { std::pair tp{ 1, 2 }; { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 12 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 12 ); } } FIT_TEST_CASE() { std::pair const tp{ 1, 2 }; { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 12 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 12 ); } } FIT_TEST_CASE() { std::array tp{{ 1, 2, 3 }}; { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } } FIT_TEST_CASE() { std::array const tp{{ 1, 2, 3 }}; { int s = 0; tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } { int s = 0; tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } ); FIT_TEST_CHECK( s == 123 ); } } FIT_TEST_CASE() { std::tuple<> tp; FIT_TEST_CHECK( tuple_for_each( tp, 11 ) == 11 ); FIT_TEST_CHECK( tuple_for_each( std::move( tp ), 12 ) == 12 ); } FIT_TEST_CASE() { FIT_TEST_CHECK( tuple_for_each( fit::pack(), 11 ) == 11 ); FIT_STATIC_TEST_CHECK( tuple_for_each( fit::pack(), 11 ) == 11 ); } FIT_TEST_CASE() { std::array tp; FIT_TEST_CHECK( tuple_for_each( tp, 11 ) == 11 ); FIT_TEST_CHECK( tuple_for_each( std::move( tp ), 12 ) == 12 ); } struct assert_is_integral { template constexpr bool operator()( T ) const { FIT_STATIC_TEST_CHECK( std::is_integral::value ); return true; } }; FIT_TEST_CASE() { #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7) auto r = tuple_for_each( std::tuple{1, 2, 3}, assert_is_integral() ); #else constexpr auto r = tuple_for_each( std::tuple{1, 2, 3}, assert_is_integral() ); #endif (void)r; } FIT_TEST_CASE() { #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7) auto r = tuple_for_each( fit::pack(1, 2, 3), assert_is_integral() ); #else constexpr auto r = tuple_for_each( fit::pack(1, 2, 3), assert_is_integral() ); #endif (void)r; }