Back to home page

EIC code displayed by LXR

 
 

    


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 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 /// @file
0009 /// Defines monomorphic dataset based on zipping of 2 other monomorphic datasets
0010 // ***************************************************************************
0011 
0012 #ifndef BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
0013 #define BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
0014 
0015 // Boost.Test
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 // **************                       zip                    ************** //
0036 // ************************************************************************** //
0037 
0038 //! Zip datasets
0039 //!
0040 //! A zip of two datasets is a dataset whose arity is the sum of the operand datasets arity. The size is given by
0041 //! the function creating the instance (see @c operator^ on datasets).
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         // Constructor
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         // forward iterator interface
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         // Data members
0072         dataset1_iter   m_iter1;
0073         dataset2_iter   m_iter2;
0074     };
0075 
0076     //! Constructor
0077     //!
0078     //! The datasets are moved and not copied.
0079     zip( DataSet1&& ds1, DataSet2&& ds2/*, data::size_t size*/ )
0080     : m_ds1( std::forward<DataSet1>( ds1 ) )
0081     , m_ds2( std::forward<DataSet2>( ds2 ) )
0082     //, m_size( size )
0083     {}
0084 
0085     //! Move constructor
0086     zip( zip&& j )
0087     : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
0088     , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
0089     //, m_size( j.m_size )
0090     {}
0091 
0092     // dataset interface
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     // Data members
0098     DataSet1        m_ds1;
0099     DataSet2        m_ds2;
0100     //data::size_t    m_size;
0101   
0102   
0103     //! Handles the sise of the resulting zipped dataset.
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 //! Zipped datasets results in a dataset.
0125 template<typename DataSet1, typename DataSet2>
0126 struct is_dataset<zip<DataSet1,DataSet2>> : mpl::true_ {};
0127 
0128 //____________________________________________________________________________//
0129 
0130 namespace result_of {
0131 
0132 //! Result type of the zip operator.
0133 template<typename DS1Gen, typename DS2Gen>
0134 struct zip {
0135     typedef monomorphic::zip<typename DS1Gen::type,typename DS2Gen::type> type;
0136 };
0137 
0138 } // namespace result_of
0139 
0140 //____________________________________________________________________________//
0141 
0142 //! Overload operator for zip support
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                                    ds_detail::zip_size( ds1, ds2 )*/ );
0152 }
0153 
0154 //____________________________________________________________________________//
0155 
0156 //! @overload boost::unit_test::data::monomorphic::operator^()
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 //! @overload boost::unit_test::data::monomorphic::operator^()
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 } // namespace monomorphic
0179 } // namespace data
0180 } // namespace unit_test
0181 } // namespace boost
0182 
0183 #include <boost/test/detail/enable_warnings.hpp>
0184 
0185 #endif // BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE
0186 
0187 #endif // BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
0188