Warning, file /include/boost/test/data/monomorphic/join.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_JOIN_HPP_112711GER
0013 #define BOOST_TEST_DATA_MONOMORPHIC_JOIN_HPP_112711GER
0014
0015
0016 #include <boost/test/data/config.hpp>
0017 #include <boost/test/data/monomorphic/fwd.hpp>
0018
0019 #include <boost/core/enable_if.hpp>
0020 #include <boost/mpl/identity.hpp>
0021
0022 #include <boost/test/detail/suppress_warnings.hpp>
0023
0024
0025
0026 namespace boost {
0027 namespace unit_test {
0028 namespace data {
0029 namespace monomorphic {
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 template<typename DataSet1, typename DataSet2>
0040 class join {
0041 typedef typename boost::decay<DataSet1>::type dataset1_decay;
0042 typedef typename boost::decay<DataSet2>::type dataset2_decay;
0043
0044 typedef typename dataset1_decay::iterator dataset1_iter;
0045 typedef typename dataset2_decay::iterator dataset2_iter;
0046
0047 using iter1_ret = decltype(*std::declval<DataSet1>().begin());
0048 using iter2_ret = decltype(*std::declval<DataSet2>().begin());
0049
0050 public:
0051
0052 static const int arity = dataset1_decay::arity;
0053
0054 using sample_t = typename std::conditional<
0055 std::is_reference<iter1_ret>::value && std::is_reference<iter2_ret>::value && std::is_same<iter1_ret, iter2_ret>::value,
0056 iter1_ret,
0057 typename std::remove_reference<iter1_ret>::type
0058 >::type
0059 ;
0060
0061 struct iterator {
0062
0063 explicit iterator( dataset1_iter&& it1, dataset2_iter&& it2, data::size_t first_size )
0064 : m_it1( std::move( it1 ) )
0065 , m_it2( std::move( it2 ) )
0066 , m_first_size( first_size )
0067 {}
0068
0069
0070
0071 sample_t operator*() const { return m_first_size > 0 ? *m_it1 : *m_it2; }
0072 void operator++() { if( m_first_size > 0 ) { --m_first_size; ++m_it1; } else ++m_it2; }
0073
0074 private:
0075
0076 dataset1_iter m_it1;
0077 dataset2_iter m_it2;
0078 data::size_t m_first_size;
0079 };
0080
0081
0082 join( DataSet1&& ds1, DataSet2&& ds2 )
0083 : m_ds1( std::forward<DataSet1>( ds1 ) )
0084 , m_ds2( std::forward<DataSet2>( ds2 ) )
0085 {}
0086
0087
0088 join( join&& j )
0089 : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
0090 , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
0091 {}
0092
0093
0094 data::size_t size() const { return m_ds1.size() + m_ds2.size(); }
0095 iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin(), m_ds1.size() ); }
0096
0097 private:
0098
0099 DataSet1 m_ds1;
0100 DataSet2 m_ds2;
0101 };
0102
0103
0104
0105
0106 template<typename DataSet1, typename DataSet2>
0107 struct is_dataset<join<DataSet1,DataSet2>> : mpl::true_ {};
0108
0109
0110
0111 namespace result_of {
0112
0113
0114 template<typename DataSet1Gen, typename DataSet2Gen>
0115 struct join {
0116 typedef monomorphic::join<typename DataSet1Gen::type,typename DataSet2Gen::type> type;
0117 };
0118
0119 }
0120
0121
0122
0123 template<typename DataSet1, typename DataSet2>
0124 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
0125 result_of::join<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
0126 >::type
0127 operator+( DataSet1&& ds1, DataSet2&& ds2 )
0128 {
0129 return join<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) );
0130 }
0131
0132
0133
0134 template<typename DataSet1, typename DataSet2>
0135 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
0136 result_of::join<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
0137 >::type
0138 operator+( DataSet1&& ds1, DataSet2&& ds2 )
0139 {
0140 return std::forward<DataSet1>( ds1 ) + data::make( std::forward<DataSet2>( ds2 ) );
0141 }
0142
0143
0144
0145 template<typename DataSet1, typename DataSet2>
0146 inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
0147 result_of::join<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
0148 >::type
0149 operator+( DataSet1&& ds1, DataSet2&& ds2 )
0150 {
0151 return data::make( std::forward<DataSet1>(ds1) ) + std::forward<DataSet2>( ds2 );
0152 }
0153
0154 }
0155 }
0156 }
0157 }
0158
0159 #include <boost/test/detail/enable_warnings.hpp>
0160
0161 #endif
0162