Add tuple_apply

This commit is contained in:
Peter Dimov
2017-06-08 17:19:28 +03:00
parent 97720ed72d
commit 359ae25630
8 changed files with 323 additions and 1 deletions

View File

@@ -38,6 +38,26 @@ int main()
}
}
{
std::tuple<int, short, char> const tp{ 1, 2, 3 };
{
int s = 0;
tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
{
int s = 0;
tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
}
#if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 8
#else
@@ -73,6 +93,26 @@ int main()
}
}
{
std::pair<int, short> const tp{ 1, 2 };
{
int s = 0;
tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 12 );
}
{
int s = 0;
tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 12 );
}
}
{
std::array<int, 3> tp{{ 1, 2, 3 }};
@@ -93,6 +133,26 @@ int main()
}
}
{
std::array<int, 3> const tp{{ 1, 2, 3 }};
{
int s = 0;
tuple_for_each( tp, [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
{
int s = 0;
tuple_for_each( std::move(tp), [&]( int x ){ s = s * 10 + x; } );
BOOST_TEST_EQ( s, 123 );
}
}
{
std::tuple<> tp;