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/test/detail/suppress_warnings.hpp>
27 //____________________________________________________________________________//
32 namespace monomorphic {
34 // ************************************************************************** //
35 // ************** grid ************** //
36 // ************************************************************************** //
39 //! Implements the dataset resulting from a cartesian product/grid operation on datasets.
41 //! The arity of the resulting dataset is the sum of the arity of its operands.
42 template<typename DataSet1, typename DataSet2>
44 typedef typename boost::decay<DataSet1>::type dataset1_decay;
45 typedef typename boost::decay<DataSet2>::type dataset2_decay;
47 typedef typename dataset1_decay::iterator dataset1_iter;
48 typedef typename dataset2_decay::iterator dataset2_iter;
54 explicit iterator( dataset1_iter iter1, DataSet2 const& ds2 )
55 : m_iter1( std::move( iter1 ) )
56 , m_iter2( std::move( ds2.begin() ) )
61 using iterator_sample = decltype(
62 sample_merge( *std::declval<dataset1_iter>(),
63 *std::declval<dataset2_iter>()) );
65 // forward iterator interface
66 auto operator*() const -> iterator_sample {
67 return sample_merge( *m_iter1, *m_iter2 );
72 if( m_ds2_pos != m_ds2->size() )
77 m_iter2 = std::move( m_ds2->begin() );
83 dataset1_iter m_iter1;
84 dataset2_iter m_iter2;
85 dataset2_decay const* m_ds2;
86 data::size_t m_ds2_pos;
90 enum { arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity };
93 grid( DataSet1&& ds1, DataSet2&& ds2 )
94 : m_ds1( std::forward<DataSet1>( ds1 ) )
95 , m_ds2( std::forward<DataSet2>( ds2 ) )
100 : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
101 , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
105 data::size_t size() const { return m_ds1.size() * m_ds2.size(); }
106 iterator begin() const { return iterator( m_ds1.begin(), m_ds2 ); }
114 //____________________________________________________________________________//
116 // A grid dataset is a dataset
117 template<typename DataSet1, typename DataSet2>
118 struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {};
120 //____________________________________________________________________________//
122 namespace result_of {
124 /// Result type of the grid operation on dataset.
125 template<typename DS1Gen, typename DS2Gen>
127 typedef monomorphic::grid<typename DS1Gen::type,typename DS2Gen::type> type;
130 } // namespace result_of
132 //____________________________________________________________________________//
135 template<typename DataSet1, typename DataSet2>
136 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
137 result_of::grid<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
139 operator*( DataSet1&& ds1, DataSet2&& ds2 )
141 BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid axes can't have infinite size" );
143 return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) );
146 //____________________________________________________________________________//
148 //! @overload boost::unit_test::data::operator*
149 template<typename DataSet1, typename DataSet2>
150 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
151 result_of::grid<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
153 operator*( DataSet1&& ds1, DataSet2&& ds2 )
155 return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2));
158 //____________________________________________________________________________//
160 //! @overload boost::unit_test::data::operator*
161 template<typename DataSet1, typename DataSet2>
162 inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
163 result_of::grid<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
165 operator*( DataSet1&& ds1, DataSet2&& ds2 )
167 return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2);
170 } // namespace monomorphic
173 } // namespace unit_test
176 #include <boost/test/detail/enable_warnings.hpp>
178 #endif // BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE
180 #endif // BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER