forked from boostorg/mp11
Add tests for tuple_for_each and empty tuples
This commit is contained in:
@@ -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 )
|
||||||
|
@@ -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();
|
||||||
}
|
}
|
||||||
|
@@ -30,10 +30,18 @@ struct assert_is_integral
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
|
constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
|
||||||
constexpr auto r = boost::tuple_for_each( tp, assert_is_integral() );
|
constexpr auto r = boost::tuple_for_each( tp, assert_is_integral() );
|
||||||
(void)r;
|
(void)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
constexpr std::tuple<> tp;
|
||||||
|
constexpr auto r = boost::tuple_for_each( tp, 11 );
|
||||||
|
static_assert( r == 11, "r == 11" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user