]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/data/monomorphic/grid.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / test / data / monomorphic / grid.hpp
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)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 ///@file
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 // ***************************************************************************
13
14 #ifndef BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
15 #define BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
16
17 // Boost.Test
18 #include <boost/test/data/config.hpp>
19
20 #if !defined(BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
21
22 #include <boost/test/data/monomorphic/fwd.hpp>
23 #include <boost/test/data/monomorphic/sample_merge.hpp>
24
25 #include <boost/mpl/identity.hpp>
26
27 #include <boost/test/detail/suppress_warnings.hpp>
28
29 //____________________________________________________________________________//
30
31 namespace boost {
32 namespace unit_test {
33 namespace data {
34 namespace monomorphic {
35
36 // ************************************************************************** //
37 // ************** grid ************** //
38 // ************************************************************************** //
39
40
41 //! Implements the dataset resulting from a cartesian product/grid operation on datasets.
42 //!
43 //! The arity of the resulting dataset is the sum of the arity of its operands.
44 template<typename DataSet1, typename DataSet2>
45 class grid {
46 typedef typename boost::decay<DataSet1>::type dataset1_decay;
47 typedef typename boost::decay<DataSet2>::type dataset2_decay;
48
49 typedef typename dataset1_decay::iterator dataset1_iter;
50 typedef typename dataset2_decay::iterator dataset2_iter;
51
52 public:
53
54 struct iterator {
55 // Constructor
56 explicit iterator( dataset1_iter iter1, DataSet2 const& ds2 )
57 : m_iter1( std::move( iter1 ) )
58 , m_iter2( std::move( ds2.begin() ) )
59 , m_ds2( &ds2 )
60 , m_ds2_pos( 0 )
61 {}
62
63 using iterator_sample = decltype(
64 sample_merge( *std::declval<dataset1_iter>(),
65 *std::declval<dataset2_iter>()) );
66
67 // forward iterator interface
68 auto operator*() const -> iterator_sample {
69 return sample_merge( *m_iter1, *m_iter2 );
70 }
71 void operator++()
72 {
73 ++m_ds2_pos;
74 if( m_ds2_pos != m_ds2->size() )
75 ++m_iter2;
76 else {
77 m_ds2_pos = 0;
78 ++m_iter1;
79 m_iter2 = std::move( m_ds2->begin() );
80 }
81 }
82
83 private:
84 // Data members
85 dataset1_iter m_iter1;
86 dataset2_iter m_iter2;
87 dataset2_decay const* m_ds2;
88 data::size_t m_ds2_pos;
89 };
90
91 public:
92 enum { arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity };
93
94 //! Constructor
95 grid( DataSet1&& ds1, DataSet2&& ds2 )
96 : m_ds1( std::forward<DataSet1>( ds1 ) )
97 , m_ds2( std::forward<DataSet2>( ds2 ) )
98 {}
99
100 //! Move constructor
101 grid( grid&& j )
102 : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
103 , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
104 {}
105
106 // dataset interface
107 data::size_t size() const { return m_ds1.size() * m_ds2.size(); }
108 iterator begin() const { return iterator( m_ds1.begin(), m_ds2 ); }
109
110 private:
111 // Data members
112 DataSet1 m_ds1;
113 DataSet2 m_ds2;
114 };
115
116 //____________________________________________________________________________//
117
118 // A grid dataset is a dataset
119 template<typename DataSet1, typename DataSet2>
120 struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {};
121
122 //____________________________________________________________________________//
123
124 namespace result_of {
125
126 /// Result type of the grid operation on dataset.
127 template<typename DS1Gen, typename DS2Gen>
128 struct grid {
129 typedef monomorphic::grid<typename DS1Gen::type,typename DS2Gen::type> type;
130 };
131
132 } // namespace result_of
133
134 //____________________________________________________________________________//
135
136 //! Grid operation
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>>
140 >::type
141 operator*( DataSet1&& ds1, DataSet2&& ds2 )
142 {
143 BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid axes can't have infinite size" );
144
145 return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) );
146 }
147
148 //____________________________________________________________________________//
149
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>>
154 >::type
155 operator*( DataSet1&& ds1, DataSet2&& ds2 )
156 {
157 return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2));
158 }
159
160 //____________________________________________________________________________//
161
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>>
166 >::type
167 operator*( DataSet1&& ds1, DataSet2&& ds2 )
168 {
169 return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2);
170 }
171
172 } // namespace monomorphic
173
174 } // namespace data
175 } // namespace unit_test
176 } // namespace boost
177
178 #include <boost/test/detail/enable_warnings.hpp>
179
180 #endif // BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE
181
182 #endif // BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
183