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 monomorphic dataset n+m dimentional *. Samples in this
10 /// dataset is grid of elements in DataSet1 and DataSet2. There will be total
11 /// |DataSet1| * |DataSet2| samples
12 // ***************************************************************************
14 #ifndef BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
15 #define BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
18 #include <boost/test/data/config.hpp>
20 #if !defined(BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
22 #include <boost/test/data/monomorphic/fwd.hpp>
23 #include <boost/test/data/monomorphic/sample_merge.hpp>
25 #include <boost/mpl/identity.hpp>
27 #include <boost/test/detail/suppress_warnings.hpp>
29 //____________________________________________________________________________//
34 namespace monomorphic {
36 // ************************************************************************** //
37 // ************** grid ************** //
38 // ************************************************************************** //
41 //! Implements the dataset resulting from a cartesian product/grid operation on datasets.
43 //! The arity of the resulting dataset is the sum of the arity of its operands.
44 template<typename DataSet1, typename DataSet2>
46 typedef typename boost::decay<DataSet1>::type dataset1_decay;
47 typedef typename boost::decay<DataSet2>::type dataset2_decay;
49 typedef typename dataset1_decay::iterator dataset1_iter;
50 typedef typename dataset2_decay::iterator dataset2_iter;
56 explicit iterator( dataset1_iter iter1, DataSet2 const& ds2 )
57 : m_iter1( std::move( iter1 ) )
58 , m_iter2( std::move( ds2.begin() ) )
63 using iterator_sample = decltype(
64 sample_merge( *std::declval<dataset1_iter>(),
65 *std::declval<dataset2_iter>()) );
67 // forward iterator interface
68 auto operator*() const -> iterator_sample {
69 return sample_merge( *m_iter1, *m_iter2 );
74 if( m_ds2_pos != m_ds2->size() )
79 m_iter2 = std::move( m_ds2->begin() );
85 dataset1_iter m_iter1;
86 dataset2_iter m_iter2;
87 dataset2_decay const* m_ds2;
88 data::size_t m_ds2_pos;
92 enum { arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity };
95 grid( DataSet1&& ds1, DataSet2&& ds2 )
96 : m_ds1( std::forward<DataSet1>( ds1 ) )
97 , m_ds2( std::forward<DataSet2>( ds2 ) )
102 : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
103 , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
107 data::size_t size() const { return m_ds1.size() * m_ds2.size(); }
108 iterator begin() const { return iterator( m_ds1.begin(), m_ds2 ); }
116 //____________________________________________________________________________//
118 // A grid dataset is a dataset
119 template<typename DataSet1, typename DataSet2>
120 struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {};
122 //____________________________________________________________________________//
124 namespace result_of {
126 /// Result type of the grid operation on dataset.
127 template<typename DS1Gen, typename DS2Gen>
129 typedef monomorphic::grid<typename DS1Gen::type,typename DS2Gen::type> type;
132 } // namespace result_of
134 //____________________________________________________________________________//
137 template<typename DataSet1, typename DataSet2>
138 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
139 result_of::grid<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
141 operator*( DataSet1&& ds1, DataSet2&& ds2 )
143 BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid axes can't have infinite size" );
145 return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) );
148 //____________________________________________________________________________//
150 //! @overload boost::unit_test::data::operator*
151 template<typename DataSet1, typename DataSet2>
152 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
153 result_of::grid<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
155 operator*( DataSet1&& ds1, DataSet2&& ds2 )
157 return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2));
160 //____________________________________________________________________________//
162 //! @overload boost::unit_test::data::operator*
163 template<typename DataSet1, typename DataSet2>
164 inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
165 result_of::grid<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
167 operator*( DataSet1&& ds1, DataSet2&& ds2 )
169 return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2);
172 } // namespace monomorphic
175 } // namespace unit_test
178 #include <boost/test/detail/enable_warnings.hpp>
180 #endif // BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE
182 #endif // BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER