Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/test/data/monomorphic/grid.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 n+m dimentional *. Samples in this
0010 /// dataset is grid of elements in DataSet1 and DataSet2. There will be total
0011 /// |DataSet1| * |DataSet2| samples
0012 // ***************************************************************************
0013 
0014 #ifndef BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
0015 #define BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
0016 
0017 // Boost.Test
0018 #include <boost/test/data/config.hpp>
0019 
0020 #if !defined(BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
0021 
0022 #include <boost/test/data/monomorphic/fwd.hpp>
0023 #include <boost/test/data/monomorphic/sample_merge.hpp>
0024 
0025 #include <boost/core/enable_if.hpp>
0026 #include <boost/mpl/identity.hpp>
0027 
0028 #include <boost/test/detail/suppress_warnings.hpp>
0029 
0030 //____________________________________________________________________________//
0031 
0032 namespace boost {
0033 namespace unit_test {
0034 namespace data {
0035 namespace monomorphic {
0036 
0037 // ************************************************************************** //
0038 // **************                       grid                    ************** //
0039 // ************************************************************************** //
0040 
0041 
0042 //! Implements the dataset resulting from a cartesian product/grid operation on datasets.
0043 //!
0044 //! The arity of the resulting dataset is the sum of the arity of its operands.
0045 template<typename DataSet1, typename DataSet2>
0046 class grid {
0047     typedef typename boost::decay<DataSet1>::type   dataset1_decay;
0048     typedef typename boost::decay<DataSet2>::type   dataset2_decay;
0049 
0050     typedef typename dataset1_decay::iterator       dataset1_iter;
0051     typedef typename dataset2_decay::iterator       dataset2_iter;
0052 
0053 public:
0054 
0055     struct iterator {
0056         // Constructor
0057         explicit    iterator( dataset1_iter iter1, DataSet2 const& ds2 )
0058         : m_iter1( std::move( iter1 ) )
0059         , m_iter2( ds2.begin() )
0060         , m_ds2( &ds2 )
0061         , m_ds2_pos( 0 )
0062         {}
0063 
0064         using iterator_sample = decltype(
0065             sample_merge( *std::declval<dataset1_iter>(),
0066                           *std::declval<dataset2_iter>()) );
0067 
0068         // forward iterator interface
0069         auto            operator*() const -> iterator_sample {
0070             return sample_merge( *m_iter1, *m_iter2 );
0071         }
0072         void            operator++()
0073         {
0074             ++m_ds2_pos;
0075             if( m_ds2_pos != m_ds2->size() )
0076                 ++m_iter2;
0077             else {
0078                 m_ds2_pos = 0;
0079                 ++m_iter1;
0080                 m_iter2 = std::move( m_ds2->begin() );
0081             }
0082         }
0083 
0084     private:
0085         // Data members
0086         dataset1_iter   m_iter1;
0087         dataset2_iter   m_iter2;
0088         dataset2_decay const* m_ds2;
0089         data::size_t    m_ds2_pos;
0090     };
0091 
0092 public:
0093     static const int arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity;
0094 
0095     //! Constructor
0096     grid( DataSet1&& ds1, DataSet2&& ds2 )
0097     : m_ds1( std::forward<DataSet1>( ds1 ) )
0098     , m_ds2( std::forward<DataSet2>( ds2 ) )
0099     {}
0100 
0101     //! Move constructor
0102     grid( grid&& j )
0103     : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
0104     , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
0105     {}
0106 
0107     // dataset interface
0108     data::size_t    size() const    {
0109       BOOST_TEST_DS_ASSERT( !m_ds1.size().is_inf() && !m_ds2.size().is_inf(), "Grid axes can't have infinite size" );
0110       return m_ds1.size() * m_ds2.size();
0111     }
0112     iterator        begin() const   { return iterator( m_ds1.begin(), m_ds2 ); }
0113 
0114 private:
0115     // Data members
0116     DataSet1             m_ds1;
0117     DataSet2             m_ds2;
0118 };
0119 
0120 //____________________________________________________________________________//
0121 
0122 // A grid dataset is a dataset
0123 template<typename DataSet1, typename DataSet2>
0124 struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {};
0125 
0126 //____________________________________________________________________________//
0127 
0128 namespace result_of {
0129 
0130 /// Result type of the grid operation on dataset.
0131 template<typename DS1Gen, typename DS2Gen>
0132 struct grid {
0133     typedef monomorphic::grid<typename DS1Gen::type,typename DS2Gen::type> type;
0134 };
0135 
0136 } // namespace result_of
0137 
0138 //____________________________________________________________________________//
0139 
0140 //! Grid operation
0141 template<typename DataSet1, typename DataSet2>
0142 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
0143                                         result_of::grid<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
0144 >::type
0145 operator*( DataSet1&& ds1, DataSet2&& ds2 )
0146 {
0147     return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ),  std::forward<DataSet2>( ds2 ) );
0148 }
0149 
0150 //____________________________________________________________________________//
0151 
0152 //! @overload boost::unit_test::data::operator*
0153 template<typename DataSet1, typename DataSet2>
0154 inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
0155                                         result_of::grid<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
0156 >::type
0157 operator*( DataSet1&& ds1, DataSet2&& ds2 )
0158 {
0159     return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2));
0160 }
0161 
0162 //____________________________________________________________________________//
0163 
0164 //! @overload boost::unit_test::data::operator*
0165 template<typename DataSet1, typename DataSet2>
0166 inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
0167                                         result_of::grid<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
0168 >::type
0169 operator*( DataSet1&& ds1, DataSet2&& ds2 )
0170 {
0171     return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2);
0172 }
0173 
0174 } // namespace monomorphic
0175 
0176 } // namespace data
0177 } // namespace unit_test
0178 } // namespace boost
0179 
0180 #include <boost/test/detail/enable_warnings.hpp>
0181 
0182 #endif // BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE
0183 
0184 #endif // BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
0185