Warning, file /include/boost/test/data/monomorphic/zip.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
0013 #define BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
0014
0015
0016 #include <boost/test/data/config.hpp>
0017
0018 #if !defined(BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
0019
0020 #include <boost/test/data/monomorphic/fwd.hpp>
0021 #include <boost/test/data/monomorphic/sample_merge.hpp>
0022
0023 #include <boost/core/enable_if.hpp>
0024 #include <boost/mpl/identity.hpp>
0025
0026 #include <boost/test/detail/suppress_warnings.hpp>
0027
0028
0029 namespace boost {
0030 namespace unit_test {
0031 namespace data {
0032 namespace monomorphic {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 template<typename DataSet1, typename DataSet2>
0043 class zip {
0044 typedef typename boost::decay<DataSet1>::type dataset1_decay;
0045 typedef typename boost::decay<DataSet2>::type dataset2_decay;
0046
0047 typedef typename dataset1_decay::iterator dataset1_iter;
0048 typedef typename dataset2_decay::iterator dataset2_iter;
0049
0050 public:
0051 static const int arity = dataset1_decay::arity + dataset2_decay::arity;
0052
0053 struct iterator {
0054
0055 explicit iterator( dataset1_iter iter1, dataset2_iter iter2 )
0056 : m_iter1( std::move( iter1 ) )
0057 , m_iter2( std::move( iter2 ) )
0058 {}
0059
0060 using iterator_sample = decltype(
0061 sample_merge( *std::declval<dataset1_iter>(),
0062 *std::declval<dataset2_iter>()) );
0063
0064
0065 auto operator*() const -> iterator_sample {
0066 return sample_merge( *m_iter1, *m_iter2 );
0067 }
0068 void operator++() { ++m_iter1; ++m_iter2; }
0069
0070 private:
0071
0072 dataset1_iter m_iter1;
0073 dataset2_iter m_iter2;
0074 };
0075
0076
0077
0078
0079 zip( DataSet1&& ds1, DataSet2&& ds2 )
0080 : m_ds1( std::forward<DataSet1>( ds1 ) )
0081 , m_ds2( std::forward<DataSet2>( ds2 ) )
0082
0083 {}
0084
0085
0086 zip( zip&& j )
0087 : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
0088 , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
0089
0090 {}
0091
0092
0093 data::size_t size() const { return zip_size(); }
0094 iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin() ); }
0095
0096 private:
0097
0098 DataSet1 m_ds1;
0099 DataSet2 m_ds2;
0100
0101
0102
0103
0104 data::size_t zip_size() const
0105 {
0106 data::size_t ds1_size = m_ds1.size();
0107 data::size_t ds2_size = m_ds2.size();
0108
0109 if( ds1_size == ds2_size )
0110 return ds1_size;
0111
0112 if( ds1_size == 1 || ds1_size.is_inf() )
0113 return ds2_size;
0114
0115 if( ds2_size == 1 || ds2_size.is_inf() )
0116 return ds1_size;
0117
0118 BOOST_TEST_DS_ERROR( "Can't zip datasets of different sizes" );
0119 }
0120 };
0121
0122
0123
0124
0125 template<typename DataSet1, typename DataSet2>
0126 struct is_dataset<zip<DataSet1,DataSet2>> : mpl::true_ {};
0127
0128
0129
0130 namespace result_of {
0131
0132
0133 template<typename DS1Gen, typename DS2Gen>
0134 struct zip {
0135 typedef monomorphic::zip<typename DS1Gen::type,typename DS2Gen::type> type;
0136 };
0137
0138 }
0139
0140
0141
0142
0143 template<typename DataSet1, typename DataSet2>
0144 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
0145 result_of::zip<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
0146 >::type
0147 operator^( DataSet1&& ds1, DataSet2&& ds2 )
0148 {
0149 return zip<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ),
0150 std::forward<DataSet2>( ds2 )
0151 );
0152 }
0153
0154
0155
0156
0157 template<typename DataSet1, typename DataSet2>
0158 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
0159 result_of::zip<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
0160 >::type
0161 operator^( DataSet1&& ds1, DataSet2&& ds2 )
0162 {
0163 return std::forward<DataSet1>( ds1 ) ^ data::make( std::forward<DataSet2>( ds2 ) );
0164 }
0165
0166
0167
0168
0169 template<typename DataSet1, typename DataSet2>
0170 inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
0171 result_of::zip<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
0172 >::type
0173 operator^( DataSet1&& ds1, DataSet2&& ds2 )
0174 {
0175 return data::make( std::forward<DataSet1>( ds1 ) ) ^ std::forward<DataSet2>( ds2 );
0176 }
0177
0178 }
0179 }
0180 }
0181 }
0182
0183 #include <boost/test/detail/enable_warnings.hpp>
0184
0185 #endif
0186
0187 #endif
0188