Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-09 10:06:17

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 /// @file
0009 /// Defines for_each_sample algorithm
0010 // ***************************************************************************
0011 
0012 #ifndef BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
0013 #define BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
0014 
0015 // Boost.Test
0016 #include <boost/test/data/config.hpp>
0017 #include <boost/test/data/size.hpp>
0018 #include <boost/test/data/index_sequence.hpp>
0019 #include <boost/test/data/monomorphic/sample_merge.hpp>
0020 #include <boost/test/data/monomorphic/fwd.hpp>
0021 
0022 // STL
0023 #include <tuple>
0024 
0025 #include <boost/test/detail/suppress_warnings.hpp>
0026 
0027 // needed for std::min
0028 #include <algorithm>
0029 
0030 //____________________________________________________________________________//
0031 
0032 namespace boost {
0033 namespace unit_test {
0034 namespace data {
0035 
0036 // ************************************************************************** //
0037 // **************              data::invoke_action             ************** //
0038 // ************************************************************************** //
0039 
0040 template<typename Action, typename T>
0041 inline void
0042 invoke_action( Action const& action, T && arg, std::false_type /* is_tuple */ )
0043 {
0044     action( std::forward<T>(arg) );
0045 }
0046 
0047 //____________________________________________________________________________//
0048 
0049 template<typename Action, typename T, std::size_t ...I>
0050 inline void
0051 invoke_action_impl( Action const& action,
0052                     T && args,
0053                     index_sequence<I...> const& )
0054 {
0055     action( std::get<I>(std::forward<T>(args))... );
0056 }
0057 
0058 //____________________________________________________________________________//
0059 
0060 template<typename Action, typename T>
0061 inline void
0062 invoke_action( Action const& action, T&& args, std::true_type /* is_tuple */ )
0063 {
0064     invoke_action_impl( action,
0065                         std::forward<T>(args),
0066                         typename make_index_sequence< 0,
0067                                                       std::tuple_size<typename std::decay<T>::type>::value
0068                                                     >::type{} );
0069 
0070 }
0071 
0072 //____________________________________________________________________________//
0073 
0074 // ************************************************************************** //
0075 // **************                for_each_sample               ************** //
0076 // ************************************************************************** //
0077 
0078 template<typename DataSet, typename Action>
0079 inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,void>::type
0080 for_each_sample( DataSet const &    samples,
0081                  Action const&      act,
0082                  data::size_t       number_of_samples = BOOST_TEST_DS_INFINITE_SIZE )
0083 {
0084     data::size_t size = (std::min)( samples.size(), number_of_samples );
0085     BOOST_TEST_DS_ASSERT( !size.is_inf(), "Dataset has infinite size. Please specify the number of samples" );
0086 
0087     auto it = samples.begin();
0088 
0089     while( size-- > 0 ) {
0090         invoke_action( act,
0091                        *it,
0092                        typename monomorphic::ds_detail::is_tuple<decltype(*it)>::type());
0093         ++it;
0094     }
0095 }
0096 
0097 //____________________________________________________________________________//
0098 
0099 template<typename DataSet, typename Action>
0100 inline typename std::enable_if<!monomorphic::is_dataset<DataSet>::value,void>::type
0101 for_each_sample( DataSet &&     samples,
0102                  Action const&      act,
0103                  data::size_t       number_of_samples = BOOST_TEST_DS_INFINITE_SIZE )
0104 {
0105     data::for_each_sample( data::make( std::forward<DataSet>(samples) ),
0106                            act,
0107                            number_of_samples );
0108 }
0109 
0110 } // namespace data
0111 } // namespace unit_test
0112 } // namespace boost
0113 
0114 #include <boost/test/detail/enable_warnings.hpp>
0115 
0116 #endif // BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
0117