1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// Defines for_each_sample algorithm
10 // ***************************************************************************
12 #ifndef BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
13 #define BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/size.hpp>
18 #include <boost/test/data/index_sequence.hpp>
19 #include <boost/test/data/monomorphic/sample_merge.hpp>
20 #include <boost/test/data/monomorphic/fwd.hpp>
25 #include <boost/test/detail/suppress_warnings.hpp>
27 // needed for std::min
30 //____________________________________________________________________________//
36 // ************************************************************************** //
37 // ************** data::invoke_action ************** //
38 // ************************************************************************** //
40 template<typename Action, typename T>
42 invoke_action( Action const& action, T && arg, std::false_type /* is_tuple */ )
44 action( std::forward<T>(arg) );
47 //____________________________________________________________________________//
49 template<typename Action, typename T, std::size_t ...I>
51 invoke_action_impl( Action const& action,
53 index_sequence<I...> const& )
55 action( std::get<I>(std::forward<T>(args))... );
58 //____________________________________________________________________________//
60 template<typename Action, typename T>
62 invoke_action( Action const& action, T&& args, std::true_type /* is_tuple */ )
64 invoke_action_impl( action,
65 std::forward<T>(args),
66 typename make_index_sequence< 0,
67 std::tuple_size<typename std::decay<T>::type>::value
72 //____________________________________________________________________________//
74 // ************************************************************************** //
75 // ************** for_each_sample ************** //
76 // ************************************************************************** //
78 template<typename DataSet, typename Action>
79 inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,void>::type
80 for_each_sample( DataSet && samples,
82 data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE )
84 data::size_t size = (std::min)( samples.size(), number_of_samples );
85 BOOST_TEST_DS_ASSERT( !size.is_inf(), "Dataset has infinite size. Please specify the number of samples" );
87 auto it = samples.begin();
92 typename monomorphic::ds_detail::is_tuple<decltype(*it)>::type());
97 //____________________________________________________________________________//
99 template<typename DataSet, typename Action>
100 inline typename std::enable_if<!monomorphic::is_dataset<DataSet>::value,void>::type
101 for_each_sample( DataSet && samples,
103 data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE )
105 data::for_each_sample( data::make( std::forward<DataSet>(samples) ),
111 } // namespace unit_test
114 #include <boost/test/detail/enable_warnings.hpp>
116 #endif // BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER