1
0
forked from boostorg/mp11

Add tests for tuple_for_each and empty tuples

This commit is contained in:
Peter Dimov
2017-05-12 23:37:37 +03:00
parent 509ce8f95e
commit d97b21261f
3 changed files with 35 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
#include <boost/integer_sequence.hpp> #include <boost/integer_sequence.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include <type_traits> #include <type_traits>
@@ -20,6 +21,15 @@ template<class Tp, std::size_t... J, class F> BOOST_CONSTEXPR F tuple_for_each_i
return (void)A{ ((void)f(std::get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f); return (void)A{ ((void)f(std::get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f);
} }
#if BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence<std::size_t>, F && f )
{
return std::forward<F>(f);
}
#endif
} // namespace detail } // namespace detail
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each( Tp && tp, F && f ) template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each( Tp && tp, F && f )

View File

@@ -91,5 +91,19 @@ int main()
} }
} }
{
std::tuple<> tp;
BOOST_TEST_EQ( boost::tuple_for_each( tp, 11 ), 11 );
BOOST_TEST_EQ( boost::tuple_for_each( std::move( tp ), 12 ), 12 );
}
{
std::array<int, 0> tp;
BOOST_TEST_EQ( boost::tuple_for_each( tp, 11 ), 11 );
BOOST_TEST_EQ( boost::tuple_for_each( std::move( tp ), 12 ), 12 );
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@@ -31,9 +31,17 @@ struct assert_is_integral
int main() int main()
{ {
constexpr std::tuple<int, short, char> tp{ 1, 2, 3 }; {
constexpr auto r = boost::tuple_for_each( tp, assert_is_integral() ); constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
(void)r; constexpr auto r = boost::tuple_for_each( tp, assert_is_integral() );
(void)r;
}
{
constexpr std::tuple<> tp;
constexpr auto r = boost::tuple_for_each( tp, 11 );
static_assert( r == 11, "r == 11" );
}
} }
#endif #endif