diff options
Diffstat (limited to 'boost/test/data/monomorphic')
-rw-r--r-- | boost/test/data/monomorphic/array.hpp | 66 | ||||
-rw-r--r-- | boost/test/data/monomorphic/collection.hpp | 68 | ||||
-rw-r--r-- | boost/test/data/monomorphic/dataset.hpp | 174 | ||||
-rw-r--r-- | boost/test/data/monomorphic/fwd.hpp | 201 | ||||
-rw-r--r-- | boost/test/data/monomorphic/generate.hpp | 53 | ||||
-rw-r--r-- | boost/test/data/monomorphic/generators.hpp | 2 | ||||
-rw-r--r-- | boost/test/data/monomorphic/generators/keywords.hpp | 2 | ||||
-rw-r--r-- | boost/test/data/monomorphic/generators/random.hpp | 12 | ||||
-rw-r--r-- | boost/test/data/monomorphic/generators/xrange.hpp | 39 | ||||
-rw-r--r-- | boost/test/data/monomorphic/grid.hpp | 132 | ||||
-rw-r--r-- | boost/test/data/monomorphic/initializer_list.hpp | 81 | ||||
-rw-r--r-- | boost/test/data/monomorphic/join.hpp | 152 | ||||
-rw-r--r-- | boost/test/data/monomorphic/singleton.hpp | 84 | ||||
-rw-r--r-- | boost/test/data/monomorphic/zip.hpp | 130 |
14 files changed, 417 insertions, 779 deletions
diff --git a/boost/test/data/monomorphic/array.hpp b/boost/test/data/monomorphic/array.hpp index 87c55e7653..6f7ed8eb3b 100644 --- a/boost/test/data/monomorphic/array.hpp +++ b/boost/test/data/monomorphic/array.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -29,41 +29,25 @@ namespace monomorphic { // ************** array ************** // // ************************************************************************** // -/// Dataset view of an C array +/// Dataset view of a C array template<typename T> -class array : public monomorphic::dataset<T> { - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; - - struct iterator : public base::iterator { - // Constructor - explicit iterator( T const* begin, data::size_t size ) - : m_it( begin ) - , m_singleton( size == 1 ) - {} - - // forward iterator interface - virtual T const& operator*() { return *m_it; } - virtual void operator++() { if( !m_singleton ) ++m_it; } - - private: - // Data members - T const* m_it; - bool m_singleton; - }; - +class array { public: + typedef T sample; + enum { arity = 1 }; + typedef T const* iterator; + // Constructor - array( T const* arr, std::size_t size ) - : m_arr( arr ) - , m_size( size ) + array( T const* arr_, std::size_t size_ ) + : m_arr( arr_ ) + , m_size( size_ ) {} // dataset interface - virtual data::size_t size() const { return m_size; } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_arr, m_size ); } + data::size_t size() const { return m_size; } + iterator begin() const { return m_arr; } private: // Data members @@ -75,34 +59,20 @@ private: //! An array dataset is a dataset template<typename T> -struct is_dataset<array<T> > : mpl::true_ {}; +struct is_dataset<array<T>> : mpl::true_ {}; } // namespace monomorphic +//____________________________________________________________________________// //! @overload boost::unit_test::data::make() template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > make( T (&a)[size] ) -{ - return monomorphic::array< typename boost::remove_const<T>::type >( a, size ); -} - -//! @overload boost::unit_test::data::make() -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > make( T const (&a)[size] ) -{ - return monomorphic::array<T>( a, size ); -} - -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > make( T a[size] ) +inline monomorphic::array<typename boost::remove_const<T>::type> +make( T (&a)[size] ) { - return monomorphic::array<T>( a, size ); + return monomorphic::array<typename boost::remove_const<T>::type>( a, size ); } - -//____________________________________________________________________________// - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/monomorphic/collection.hpp b/boost/test/data/monomorphic/collection.hpp index 5666a62f8d..49e81458bf 100644 --- a/boost/test/data/monomorphic/collection.hpp +++ b/boost/test/data/monomorphic/collection.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -35,54 +35,28 @@ namespace monomorphic { //! This dataset is applicable to any container implementing a forward iterator. Note that //! container with one element will be considered as singletons. //! This dataset is constructible with the @ref boost::unit_test::data::make function. -//! -//! For compilers supporting r-value references, the collection is moved instead of copied. template<typename C> -class collection : public monomorphic::dataset<typename boost::decay<C>::type::value_type> { +class collection { typedef typename boost::decay<C>::type col_type; - typedef typename col_type::value_type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; - - struct iterator : public base::iterator { - // Constructor - explicit iterator( collection<C> const& owner ) - : m_iter( owner.col().begin() ) - , m_singleton( owner.col().size() == 1 ) - {} - - // forward iterator interface - virtual T const& operator*() { return *m_iter; } - virtual void operator++() { if( !m_singleton ) ++m_iter; } - - private: - // Data members - typename col_type::const_iterator m_iter; - bool m_singleton; - }; - public: + typedef typename col_type::value_type sample; + enum { arity = 1 }; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - //! Constructor - //! The collection is moved - explicit collection( C&& col ) : m_col( std::forward<C>(col) ) {} + typedef typename col_type::const_iterator iterator; + + //! Constructor consumed a temporary collection or stores a reference + explicit collection( C&& col ) : m_col( std::forward<C>(col) ) {} //! Move constructor collection( collection&& c ) : m_col( std::forward<C>( c.m_col ) ) {} -#else - //! Constructor - //! The collection is copied - explicit collection( C const& col ) : m_col( col ) {} -#endif //! Returns the underlying collection - C const& col() const { return m_col; } + C const& col() const { return m_col; } - // dataset interface - virtual data::size_t size() const { return m_col.size(); } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( *this ); } + //! dataset interface + data::size_t size() const { return m_col.size(); } + iterator begin() const { return m_col.begin(); } private: // Data members @@ -93,27 +67,19 @@ private: //! A collection from a forward iterable container is a dataset. template<typename C> -struct is_dataset<collection<C> > : mpl::true_ {}; +struct is_dataset<collection<C>> : mpl::true_ {}; } // namespace monomorphic +//____________________________________________________________________________// + //! @overload boost::unit_test::data::make() template<typename C> -inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, - monomorphic::collection<C> >::type -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +inline typename std::enable_if<is_forward_iterable<C>::value,monomorphic::collection<C>>::type make( C&& c ) { return monomorphic::collection<C>( std::forward<C>(c) ); } -#else -make( C const& c ) -{ - return monomorphic::collection<C>( c ); -} -#endif - -//____________________________________________________________________________// } // namespace data } // namespace unit_test diff --git a/boost/test/data/monomorphic/dataset.hpp b/boost/test/data/monomorphic/dataset.hpp deleted file mode 100644 index 122dbea8c5..0000000000 --- a/boost/test/data/monomorphic/dataset.hpp +++ /dev/null @@ -1,174 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -/// @file -/// Defines monomorphic dataset interface -// -// *************************************************************************** - -#ifndef BOOST_TEST_DATA_MONOMORPHIC_DATASET_HPP_102211GER -#define BOOST_TEST_DATA_MONOMORPHIC_DATASET_HPP_102211GER - -// Boost.Test -#include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/fwd.hpp> - -// STL -#ifndef BOOST_NO_CXX11_HDR_TUPLE -#include <tuple> -#endif -//#include <stdexcept> - -#include <boost/test/detail/suppress_warnings.hpp> - -//____________________________________________________________________________// - -namespace boost { -namespace unit_test { -namespace data { -namespace monomorphic { - -// ************************************************************************** // -// ************** monomorphic::traits ************** // -// ************************************************************************** // - -template<typename T> -struct traits { - // type of the reference to sample returned by iterator - typedef T const& ref_type; - - template<typename Action> - static void - invoke_action( ref_type arg, Action const& action ) - { - action( arg ); - } -}; - -//____________________________________________________________________________// - -#ifndef BOOST_NO_CXX11_HDR_TUPLE -// !! ?? reimplement using variadics -template<typename T1, typename T2> -struct traits<std::tuple<T1,T2>> { - // type of the reference to sample returned by iterator - typedef std::tuple<T1 const&,T2 const&> ref_type; - - template<typename Action> - static void - invoke_action( ref_type arg, Action const& action ) - { - action( std::get<0>(arg), std::get<1>(arg) ); - } -}; - -//____________________________________________________________________________// - -template<typename T1, typename T2, typename T3> -struct traits<std::tuple<T1,T2,T3>> { - // type of the reference to sample returned by iterator - typedef std::tuple<T1 const&,T2 const&,T3 const&> ref_type; - - template<typename Action> - static void - invoke_action( ref_type arg, Action const& action ) - { - action( std::get<0>(arg), std::get<1>(arg), std::get<2>(arg) ); - } -}; - -//____________________________________________________________________________// - -#endif - -// ************************************************************************** // -// ************** monomorphic::dataset ************** // -// ************************************************************************** // - -//!@brief Dataset base class -//! -//! This class defines the dataset concept, which is an implementation of a sequence. -//! Each dataset should implement -//! - the @c size -//! - the @c begin function, which provides a forward iterator on the beginning of the sequence. The returned -//! iterator should be incrementable a number of times corresponding to the returned size. -//! -template<typename T> -class dataset { -public: - //! Type of the samples in this dataset - typedef T data_type; - - virtual ~dataset() - {} - - //! Interface of the dataset iterator - class iterator { - public: - typedef typename monomorphic::traits<T>::ref_type ref_type; - - virtual ~iterator() {} - - // forward iterator interface - virtual ref_type operator*() = 0; - virtual void operator++() = 0; - }; - - //! Type of the iterator - typedef boost::shared_ptr<iterator> iter_ptr; - - //! Dataset size - virtual data::size_t size() const = 0; - - //! Iterator to use to iterate over this dataset - virtual iter_ptr begin() const = 0; -}; - -} // namespace monomorphic - -// ************************************************************************** // -// ************** for_each_sample ************** // -// ************************************************************************** // - -template<typename SampleType, typename Action> -inline void -for_each_sample( monomorphic::dataset<SampleType> const& ds, - Action const& act, - data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE ) -{ - data::size_t size = (std::min)( ds.size(), number_of_samples ); - BOOST_TEST_DS_ASSERT( !size.is_inf(), "Dataset has infinite size. Please specify the number of samples" ); - - typename monomorphic::dataset<SampleType>::iter_ptr it = ds.begin(); - - while( size-- > 0 ) { - monomorphic::traits<SampleType>::invoke_action( **it, act ); - ++(*it); - } -} - -//____________________________________________________________________________// - -template<typename SampleType, typename Action> -inline typename BOOST_TEST_ENABLE_IF<!monomorphic::is_dataset<SampleType>::value,void>::type -for_each_sample( SampleType const& samples, - Action const& act, - data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE ) -{ - data::for_each_sample( data::make( samples ), act, number_of_samples ); -} - -//____________________________________________________________________________// - -} // namespace data -} // namespace unit_test -} // namespace boost - -#include <boost/test/detail/enable_warnings.hpp> - -#endif // BOOST_TEST_DATA_MONOMORPHIC_DATASET_HPP_102211GER - diff --git a/boost/test/data/monomorphic/fwd.hpp b/boost/test/data/monomorphic/fwd.hpp index 9ff4955432..26c36743df 100644 --- a/boost/test/data/monomorphic/fwd.hpp +++ b/boost/test/data/monomorphic/fwd.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2012-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -18,22 +18,17 @@ #include <boost/test/utils/is_forward_iterable.hpp> - // Boost -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES -#include <boost/utility/enable_if.hpp> -#include <boost/type_traits/add_const.hpp> -#else -#include <boost/utility/declval.hpp> -#endif #include <boost/type_traits/remove_const.hpp> +#include <boost/type_traits/remove_reference.hpp> +#include <boost/type_traits/is_array.hpp> #include <boost/mpl/bool.hpp> -#include <boost/smart_ptr/make_shared.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/type_traits/decay.hpp> #include <boost/test/detail/suppress_warnings.hpp> +// STL +#include <initializer_list> + //____________________________________________________________________________// namespace boost { @@ -44,10 +39,8 @@ namespace monomorphic { #if !defined(BOOST_TEST_DOXYGEN_DOC__) -template<typename T> -struct traits; -template<typename T> +template<typename T, typename Specific> class dataset; template<typename T> @@ -58,12 +51,10 @@ class collection; template<typename T> class array; -#endif -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES -# define BOOST_TEST_ENABLE_IF std::enable_if -#else -# define BOOST_TEST_ENABLE_IF boost::enable_if_c +template<typename T> +class init_list; + #endif // ************************************************************************** // @@ -74,25 +65,24 @@ class array; template<typename DataSet> struct is_dataset : mpl::false_ {}; +//____________________________________________________________________________// + //! A reference to a dataset is a dataset template<typename DataSet> struct is_dataset<DataSet&> : is_dataset<DataSet> {}; +//____________________________________________________________________________// + //! A const dataset is a dataset template<typename DataSet> struct is_dataset<DataSet const> : is_dataset<DataSet> {}; -//____________________________________________________________________________// - } // namespace monomorphic // ************************************************************************** // // ************** data::make ************** // // ************************************************************************** // -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - - //! @brief Creates a dataset from a value, a collection or an array //! //! This function has several overloads: @@ -113,201 +103,74 @@ struct is_dataset<DataSet const> : is_dataset<DataSet> {}; //! template<typename T, std::size_t size> monomorphic::array<T> make( T (&a)[size] ); //! @endcode template<typename DataSet> -inline typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value,DataSet>::type +inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,DataSet>::type make(DataSet&& ds) { return std::forward<DataSet>( ds ); } +//____________________________________________________________________________// // warning: doxygen is apparently unable to handle @overload from different files, so if the overloads // below are not declared with @overload in THIS file, they do not appear in the documentation. -// fwrd declaration for singletons //! @overload boost::unit_test::data::make() template<typename T> -inline typename BOOST_TEST_ENABLE_IF<!is_forward_iterable<T>::value && - !monomorphic::is_dataset<T>::value && - !boost::is_array< typename boost::remove_reference<T>::type >::value, - monomorphic::singleton<T> >::type +inline typename std::enable_if<!is_forward_iterable<T>::value && + !monomorphic::is_dataset<T>::value && + !is_array<typename remove_reference<T>::type>::value, + monomorphic::singleton<T>>::type make( T&& v ); +//____________________________________________________________________________// //! @overload boost::unit_test::data::make() template<typename C> -inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, - monomorphic::collection<C> >::type +inline typename std::enable_if<is_forward_iterable<C>::value,monomorphic::collection<C>>::type make( C&& c ); - -#else // !BOOST_NO_CXX11_RVALUE_REFERENCES - -//! @overload boost::unit_test:data::make() -template<typename DataSet> -inline typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value,DataSet const&>::type -make(DataSet const& ds) -{ - return ds; -} - - -// fwrd declaration for singletons -#if !(defined(BOOST_MSVC) && (BOOST_MSVC < 1600)) -//! @overload boost::unit_test::data::make() -template<typename T> -inline typename BOOST_TEST_ENABLE_IF<!is_forward_iterable<T>::value && - !monomorphic::is_dataset<T>::value && - !boost::is_array< typename boost::remove_reference<T>::type >::value, - monomorphic::singleton<T> >::type -make( T const& v ); -#endif - - -// fwrd declaration for collections -//! @overload boost::unit_test::data::make() -template<typename C> -inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, - monomorphic::collection<C> >::type -make( C const& c ); - //____________________________________________________________________________// - - -#endif // !BOOST_NO_CXX11_RVALUE_REFERENCES - - - - -// fwrd declarations //! @overload boost::unit_test::data::make() template<typename T, std::size_t size> inline monomorphic::array< typename boost::remove_const<T>::type > make( T (&a)[size] ); -// apparently some compilers (eg clang-3.4 on linux) have trouble understanding -// the previous line for T being const -//! @overload boost::unit_test::data::make() -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > -make( T const (&)[size] ); - -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > -make( T a[size] ); - - +//____________________________________________________________________________// //! @overload boost::unit_test::data::make() inline monomorphic::singleton<char*> make( char* str ); +//____________________________________________________________________________// + //! @overload boost::unit_test::data::make() inline monomorphic::singleton<char const*> make( char const* str ); - - //____________________________________________________________________________// +//! @overload boost::unit_test::data::make() +template<typename T> +inline monomorphic::init_list<T> +make( std::initializer_list<T>&& ); +//____________________________________________________________________________// namespace result_of { -#ifndef BOOST_NO_CXX11_DECLTYPE //! Result of the make call. template<typename DataSet> -struct make -{ - typedef decltype(data::make(boost::declval<DataSet>())) type; -}; -#else - -// explicit specialisation, cumbersome - -template <typename DataSet, typename Enable = void> -struct make; - -template <typename DataSet> -struct make< - DataSet const&, - typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value>::type - > -{ - typedef DataSet const& type; -}; - -template <typename T> -struct make< - T, - typename BOOST_TEST_ENABLE_IF< (!is_forward_iterable<T>::value && - !monomorphic::is_dataset<T>::value && - !boost::is_array< typename boost::remove_reference<T>::type >::value) - >::type - > -{ - typedef monomorphic::singleton<T> type; -}; - -template <typename C> -struct make< - C, - typename BOOST_TEST_ENABLE_IF< is_forward_iterable<C>::value>::type - > -{ - typedef monomorphic::collection<C> type; -}; - -#if 1 -template <typename T, std::size_t size> -struct make<T [size]> -{ - typedef monomorphic::array<typename boost::remove_const<T>::type> type; +struct make { + typedef decltype( data::make( declval<DataSet>() ) ) type; }; -#endif - -template <typename T, std::size_t size> -struct make<T (&)[size]> -{ - typedef monomorphic::array<typename boost::remove_const<T>::type> type; -}; - -template <typename T, std::size_t size> -struct make<T const (&)[size]> -{ - typedef monomorphic::array<typename boost::remove_const<T>::type> type; -}; - -template <> -struct make<char*> -{ - typedef monomorphic::singleton<char*> type; -}; - -template <> -struct make<char const*> -{ - typedef monomorphic::singleton<char const*> type; -}; - -#endif // BOOST_NO_CXX11_DECLTYPE - } // namespace result_of - - - -//____________________________________________________________________________// - } // namespace data } // namespace unit_test } // namespace boost - - - - #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER diff --git a/boost/test/data/monomorphic/generate.hpp b/boost/test/data/monomorphic/generate.hpp index c5ff1d699b..af3b5c0bb9 100644 --- a/boost/test/data/monomorphic/generate.hpp +++ b/boost/test/data/monomorphic/generate.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -36,44 +36,43 @@ namespace monomorphic { * - random_t * * The generator concept is the following: - * - the type of the generated samples is given by field @c data_type + * - the type of the generated samples is given by field @c sample * - the member function @c capacity should return the size of the collection being generated (potentially infinite) * - the member function @c next should change the state of the generator to the next generated value * - the member function @c reset should put the state of the object in the same state as right after its instanciation */ template<typename Generator> -class generated_by : public monomorphic::dataset<typename Generator::data_type> { - typedef typename Generator::data_type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; +class generated_by { +public: + typedef typename Generator::sample sample; + + enum { arity = 1 }; - struct iterator : public base::iterator { + struct iterator { // Constructor explicit iterator( Generator& gen ) - : m_gen( gen ) + : m_gen( &gen ) { - if(m_gen.capacity() > 0) { - m_gen.reset(); + if(m_gen->capacity() > 0) { + m_gen->reset(); ++*this; } } // forward iterator interface - virtual T const& operator*() { return m_curr_sample; } - virtual void operator++() { m_curr_sample = m_gen.next(); } + sample const& operator*() const { return m_curr_sample; } + void operator++() { m_curr_sample = m_gen->next(); } private: // Data members - Generator& m_gen; - T m_curr_sample; + Generator* m_gen; + sample m_curr_sample; }; -public: - enum { arity = 1 }; + typedef Generator generator_type; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES // Constructor - explicit generated_by( Generator&& G ) + explicit generated_by( Generator&& G ) : m_generator( std::forward<Generator>(G) ) {} @@ -81,29 +80,23 @@ public: generated_by( generated_by&& rhs ) : m_generator( std::forward<Generator>(rhs.m_generator) ) {} -#else - // Constructor - explicit generated_by( Generator const& G ) - : m_generator( G ) - {} -#endif //! Size of the underlying dataset - data::size_t size() const { return m_generator.capacity(); } + data::size_t size() const { return m_generator.capacity(); } //! Iterator on the beginning of the dataset - virtual iter_ptr begin() const { return boost::make_shared<iterator>( boost::ref(const_cast<Generator&>(m_generator)) ); } + iterator begin() const { return iterator( boost::ref(const_cast<Generator&>(m_generator)) ); } private: // Data members - Generator m_generator; + Generator m_generator; }; +//____________________________________________________________________________// //! A generated dataset is a dataset. template<typename Generator> -struct is_dataset<generated_by<Generator> > : mpl::true_ {}; - +struct is_dataset<generated_by<Generator>> : mpl::true_ {}; } // namespace monomorphic } // namespace data diff --git a/boost/test/data/monomorphic/generators.hpp b/boost/test/data/monomorphic/generators.hpp index aa74d7abb1..108d4ba58d 100644 --- a/boost/test/data/monomorphic/generators.hpp +++ b/boost/test/data/monomorphic/generators.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/test/data/monomorphic/generators/keywords.hpp b/boost/test/data/monomorphic/generators/keywords.hpp index 4983678f95..de6a4e89e5 100644 --- a/boost/test/data/monomorphic/generators/keywords.hpp +++ b/boost/test/data/monomorphic/generators/keywords.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) diff --git a/boost/test/data/monomorphic/generators/random.hpp b/boost/test/data/monomorphic/generators/random.hpp index a82eef103d..24a1df3c64 100644 --- a/boost/test/data/monomorphic/generators/random.hpp +++ b/boost/test/data/monomorphic/generators/random.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -36,7 +36,7 @@ namespace data { namespace { nfp::keyword<struct seed_t> seed; -nfp::keyword<struct distrbution_t> distribution; +nfp::keyword<struct distribution_t> distribution; nfp::keyword<struct engine_t> engine; } // local namespace @@ -47,7 +47,7 @@ template<typename SampleType> struct default_distribution { typedef typename mpl::if_<std::is_integral<SampleType>, std::uniform_int_distribution<SampleType>, - std::uniform_real_distribution<SampleType> >::type type; + std::uniform_real_distribution<SampleType>>::type type; }; } // namespace ds_detail @@ -66,7 +66,7 @@ template<typename SampleType = double, typename EngineType = std::default_random_engine> class random_t { public: - typedef SampleType data_type; + typedef SampleType sample; typedef DistributionType distr_type; typedef EngineType engine_type; @@ -127,7 +127,7 @@ private: //! //! The function returns an object that implements the dataset API. //! @note This function is available only for C++11 capable compilers. -inline monomorphic::generated_by< monomorphic::random_t<> > random() +inline monomorphic::generated_by< monomorphic::random_t<>> random() { return monomorphic::generated_by<monomorphic::random_t<>>( monomorphic::random_t<>() ); } @@ -136,7 +136,7 @@ inline monomorphic::generated_by< monomorphic::random_t<> > random() /// @overload boost::unit_test::data::random() template<typename SampleType> -inline monomorphic::generated_by< monomorphic::random_t<SampleType> > +inline monomorphic::generated_by< monomorphic::random_t<SampleType>> random( SampleType begin, SampleType end ) { typedef monomorphic::random_t<SampleType> Gen; diff --git a/boost/test/data/monomorphic/generators/xrange.hpp b/boost/test/data/monomorphic/generators/xrange.hpp index 55a51110b4..02da352adf 100644 --- a/boost/test/data/monomorphic/generators/xrange.hpp +++ b/boost/test/data/monomorphic/generators/xrange.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -49,14 +49,14 @@ namespace monomorphic { template<typename SampleType, typename StepType=SampleType> class xrange_t { public: - typedef SampleType data_type; + typedef SampleType sample; - xrange_t( SampleType const& begin, StepType const& step, data::size_t size ) - : m_begin( begin ) - , m_curr( begin ) - , m_step( step ) + xrange_t( SampleType const& begin_, StepType const& step_, data::size_t size_ ) + : m_begin( begin_ ) + , m_curr( begin_ ) + , m_step( step_ ) , m_index( 0 ) - , m_size( size ) + , m_size( size_ ) {} // Generator interface @@ -159,7 +159,7 @@ struct make_xrange { //! //! @note the step size cannot be null, and it should be positive if @c begin_val < @c end_val, negative otherwise. template<typename SampleType, typename Params> -inline monomorphic::generated_by<monomorphic::xrange_t<SampleType> > +inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>> xrange( Params const& params ) { return monomorphic::ds_detail::make_xrange<SampleType>::_( params ); @@ -169,7 +169,7 @@ xrange( Params const& params ) /// @overload boost::unit_test::data::xrange() template<typename SampleType> -inline monomorphic::generated_by<monomorphic::xrange_t<SampleType> > +inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>> xrange( SampleType const& end_val ) { return monomorphic::ds_detail::make_xrange<SampleType>::_( data::end=end_val ); @@ -179,22 +179,23 @@ xrange( SampleType const& end_val ) /// @overload boost::unit_test::data::xrange() template<typename SampleType, typename Params> -inline typename enable_if_c<nfp::is_named_params<Params>::value,monomorphic::generated_by<monomorphic::xrange_t<SampleType> > >::type +inline typename enable_if_c<nfp::is_named_param_pack<Params>::value, + monomorphic::generated_by<monomorphic::xrange_t<SampleType>>>::type xrange( SampleType const& end_val, Params const& params ) { - return monomorphic::ds_detail::make_xrange<SampleType>:: - _(( params, data::end=end_val )); + return monomorphic::ds_detail::make_xrange<SampleType>::_(( params, data::end=end_val )); } //____________________________________________________________________________// /// @overload boost::unit_test::data::xrange() template<typename SampleType> -inline monomorphic::generated_by<monomorphic::xrange_t<SampleType> > +inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>> xrange( SampleType const& begin_val, SampleType const& end_val ) { - return monomorphic::ds_detail::make_xrange<SampleType>:: - _(( data::begin=begin_val, data::end=end_val )); + return monomorphic::ds_detail::make_xrange<SampleType>::_(( + data::begin=begin_val, + data::end=end_val )); } //____________________________________________________________________________// @@ -203,11 +204,13 @@ xrange( SampleType const& begin_val, SampleType const& end_val ) /// @overload boost::unit_test::data::xrange() template<typename SampleType,typename StepType> -inline monomorphic::generated_by<monomorphic::xrange_t<SampleType> > +inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>> xrange( SampleType const& begin_val, SampleType const& end_val, StepType const& step_val ) { - return monomorphic::ds_detail::make_xrange<SampleType,StepType>:: - _(( data::begin=begin_val, data::end=end_val, data::step=step_val )); + return monomorphic::ds_detail::make_xrange<SampleType,StepType>::_(( + data::begin=begin_val, + data::end=end_val, + data::step=step_val )); } //____________________________________________________________________________// diff --git a/boost/test/data/monomorphic/grid.hpp b/boost/test/data/monomorphic/grid.hpp index 00aaa56cd1..6af906c62c 100644 --- a/boost/test/data/monomorphic/grid.hpp +++ b/boost/test/data/monomorphic/grid.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -7,8 +7,8 @@ // ///@file /// Defines monomorphic dataset n+m dimentional *. Samples in this -/// dataset is grid of elements in DS1 and DS2. There will be total -/// |DS1| * |DS2| samples +/// dataset is grid of elements in DataSet1 and DataSet2. There will be total +/// |DataSet1| * |DataSet2| samples // *************************************************************************** #ifndef BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER @@ -17,10 +17,11 @@ // Boost.Test #include <boost/test/data/config.hpp> - #if !defined(BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__) -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/traits.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + #include <boost/test/detail/suppress_warnings.hpp> //____________________________________________________________________________// @@ -36,7 +37,7 @@ namespace ds_detail { template<typename T1, typename T2> struct grid_traits { typedef std::tuple<T1,T2> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, T2 const& a2) @@ -50,7 +51,7 @@ struct grid_traits { template<typename T1, typename T2,typename T3> struct grid_traits<T1,std::tuple<T2,T3>> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, std::tuple<T2 const&,T3 const&> const& a2) @@ -64,7 +65,7 @@ struct grid_traits<T1,std::tuple<T2,T3>> { template<typename T1, typename T2,typename T3> struct grid_traits<std::tuple<T1,T2>,T3> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(std::tuple<T1 const&,T2 const&> const& a1, T3 const& a2) @@ -85,82 +86,83 @@ struct grid_traits<std::tuple<T1,T2>,T3> { //! Implements the dataset resulting from a cartesian product/grid operation on datasets. //! //! The arity of the resulting dataset is the sum of the arity of its operands. -template<typename DS1, typename DS2> -class grid : public monomorphic::dataset<typename ds_detail::grid_traits<typename boost::decay<DS1>::type::data_type, - typename boost::decay<DS2>::type::data_type>::type> { - typedef typename boost::decay<DS1>::type::data_type T1; - typedef typename boost::decay<DS2>::type::data_type T2; +template<typename DataSet1, typename DataSet2> +class grid { + typedef typename boost::decay<DataSet1>::type dataset1_decay; + typedef typename boost::decay<DataSet2>::type dataset2_decay; + + typedef typename dataset1_decay::iterator dataset1_iter; + typedef typename dataset2_decay::iterator dataset2_iter; - typedef typename monomorphic::dataset<T1>::iter_ptr ds1_iter_ptr; - typedef typename monomorphic::dataset<T2>::iter_ptr ds2_iter_ptr; + typedef typename dataset1_decay::sample sample1; + typedef typename dataset2_decay::sample sample2; - typedef typename ds_detail::grid_traits<T1,T2>::type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; +public: + typedef typename ds_detail::grid_traits<sample1,sample2>::type sample; - struct iterator : public base::iterator { - typedef typename monomorphic::traits<T>::ref_type ref_type; + struct iterator { + typedef typename data::traits<sample>::ref_type ref_type; // Constructor - explicit iterator( ds1_iter_ptr iter1, DS2 const& ds2 ) - : m_iter1( iter1 ) - , m_iter2( ds2.begin() ) - , m_ds2( ds2 ) + explicit iterator( dataset1_iter iter1, DataSet2 const& ds2 ) + : m_iter1( std::move( iter1 ) ) + , m_iter2( std::move( ds2.begin() ) ) + , m_ds2( &ds2 ) , m_ds2_pos( 0 ) {} // forward iterator interface - virtual ref_type operator*() { return ds_detail::grid_traits<T1,T2>::tuple_merge( **m_iter1, **m_iter2 ); } - virtual void operator++() + ref_type operator*() const { return ds_detail::grid_traits<sample1,sample2>::tuple_merge( *m_iter1, *m_iter2 ); } + void operator++() { ++m_ds2_pos; - if( m_ds2_pos != m_ds2.size() ) - ++(*m_iter2); + if( m_ds2_pos != m_ds2->size() ) + ++m_iter2; else { m_ds2_pos = 0; - ++(*m_iter1); - m_iter2 = m_ds2.begin(); + ++m_iter1; + m_iter2 = std::move( m_ds2->begin() ); } } private: // Data members - ds1_iter_ptr m_iter1; - ds2_iter_ptr m_iter2; - DS2 const& m_ds2; + dataset1_iter m_iter1; + dataset2_iter m_iter2; + dataset2_decay const* m_ds2; data::size_t m_ds2_pos; }; public: - enum { arity = boost::decay<DS1>::type::arity + boost::decay<DS2>::type::arity }; + enum { arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity }; //! Constructor - grid( DS1&& ds1, DS2&& ds2 ) - : m_ds1( std::forward<DS1>( ds1 ) ) - , m_ds2( std::forward<DS2>( ds2 ) ) + grid( DataSet1&& ds1, DataSet2&& ds2 ) + : m_ds1( std::forward<DataSet1>( ds1 ) ) + , m_ds2( std::forward<DataSet2>( ds2 ) ) {} //! Move constructor grid( grid&& j ) - : m_ds1( std::forward<DS1>( j.m_ds1 ) ) - , m_ds2( std::forward<DS2>( j.m_ds2 ) ) + : m_ds1( std::forward<DataSet1>( j.m_ds1 ) ) + , m_ds2( std::forward<DataSet2>( j.m_ds2 ) ) {} // dataset interface - virtual data::size_t size() const { return m_ds1.size() * m_ds2.size(); } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_ds1.begin(), m_ds2 ); } + data::size_t size() const { return m_ds1.size() * m_ds2.size(); } + iterator begin() const { return iterator( m_ds1.begin(), m_ds2 ); } private: // Data members - DS1 m_ds1; - DS2 m_ds2; + DataSet1 m_ds1; + DataSet2 m_ds2; }; //____________________________________________________________________________// // A grid dataset is a dataset -template<typename DS1, typename DS2> -struct is_dataset<grid<DS1,DS2> > : mpl::true_ {}; +template<typename DataSet1, typename DataSet2> +struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {}; //____________________________________________________________________________// @@ -176,42 +178,42 @@ struct grid { //____________________________________________________________________________// - - //! Grid operation -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::grid<mpl::identity<DS1>,mpl::identity<DS2>> +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value, + result_of::grid<mpl::identity<DataSet1>,mpl::identity<DataSet2>> >::type -operator*( DS1&& ds1, DS2&& ds2 ) +operator*( DataSet1&& ds1, DataSet2&& ds2 ) { - BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid dimension can't have infinite size" ); + BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid axes can't have infinite size" ); - return grid<DS1,DS2>( std::forward<DS1>( ds1 ), std::forward<DS2>( ds2 ) ); + return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) ); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::operator* -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::grid<mpl::identity<DS1>,data::result_of::make<DS2>> +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value, + result_of::grid<mpl::identity<DataSet1>,data::result_of::make<DataSet2>> >::type -operator*( DS1&& ds1, DS2&& ds2 ) +operator*( DataSet1&& ds1, DataSet2&& ds2 ) { - return std::forward<DS1>(ds1) * data::make(std::forward<DS2>(ds2)); + return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2)); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::operator* -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::grid<data::result_of::make<DS1>,mpl::identity<DS2>> +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value, + result_of::grid<data::result_of::make<DataSet1>,mpl::identity<DataSet2>> >::type -operator*( DS1&& ds1, DS2&& ds2 ) +operator*( DataSet1&& ds1, DataSet2&& ds2 ) { - return data::make(std::forward<DS1>(ds1)) * std::forward<DS2>(ds2); + return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2); } -//____________________________________________________________________________// - } // namespace monomorphic } // namespace data diff --git a/boost/test/data/monomorphic/initializer_list.hpp b/boost/test/data/monomorphic/initializer_list.hpp new file mode 100644 index 0000000000..3221597396 --- /dev/null +++ b/boost/test/data/monomorphic/initializer_list.hpp @@ -0,0 +1,81 @@ +// (C) Copyright Gennadiy Rozental 2001. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/test for the library home page. +// +///@file +///Defines monomorphic dataset based on C++11 initializer_list template +// *************************************************************************** + +#ifndef BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER +#define BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER + +// Boost.Test +#include <boost/test/data/config.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + +//____________________________________________________________________________// + +namespace boost { +namespace unit_test { +namespace data { +namespace monomorphic { + +// ************************************************************************** // +// ************** array ************** // +// ************************************************************************** // + +/// Dataset view of a C array +template<typename T> +class init_list { +public: + typedef T sample; + + enum { arity = 1 }; + + typedef T const* iterator; + + //! Constructor swallows initializer_list + init_list( std::initializer_list<T>&& il ) + : m_data( std::forward<std::initializer_list<T>>( il ) ) + {} + + //! dataset interface + data::size_t size() const { return m_data.size(); } + iterator begin() const { return m_data.begin(); } + +private: + // Data members + std::initializer_list<T> m_data; +}; + +//____________________________________________________________________________// + +//! An array dataset is a dataset +template<typename T> +struct is_dataset<init_list<T>> : mpl::true_ {}; + +} // namespace monomorphic + +//____________________________________________________________________________// + +//! @overload boost::unit_test::data::make() +template<typename T> +inline monomorphic::init_list<T> +make( std::initializer_list<T>&& il ) +{ + return monomorphic::init_list<T>( std::forward<std::initializer_list<T>>( il ) ); +} + +} // namespace data +} // namespace unit_test +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER + diff --git a/boost/test/data/monomorphic/join.hpp b/boost/test/data/monomorphic/join.hpp index 94b25c78e2..f817994dd3 100644 --- a/boost/test/data/monomorphic/join.hpp +++ b/boost/test/data/monomorphic/join.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -33,157 +33,111 @@ namespace monomorphic { //! //! The size of the resulting dataset is the sum of the two underlying datasets. The arity of the datasets //! should match. -template<typename DS1, typename DS2> -class join : public monomorphic::dataset<typename boost::decay<DS1>::type::data_type> { - typedef typename boost::decay<DS1>::type::data_type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; +template<typename DataSet1, typename DataSet2> +class join { + typedef typename boost::decay<DataSet1>::type dataset1_decay; + typedef typename boost::decay<DataSet2>::type dataset2_decay; - struct iterator : public base::iterator { + typedef typename dataset1_decay::iterator dataset1_iter; + typedef typename dataset2_decay::iterator dataset2_iter; +public: + typedef typename dataset1_decay::sample sample; + + enum { arity = dataset1_decay::arity }; + + struct iterator { // Constructor - explicit iterator( iter_ptr it1, iter_ptr it2, data::size_t first_size ) -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - : m_it1( std::move(it1) ) - , m_it2( std::move(it2) ) -#else - : m_it1( it1 ) - , m_it2( it2 ) -#endif + explicit iterator( dataset1_iter it1, dataset2_iter it2, data::size_t first_size ) + : m_it1( std::move( it1 ) ) + , m_it2( std::move( it2 ) ) , m_first_size( first_size ) {} // forward iterator interface - virtual T const& operator*() { return m_first_size > 0 ? **m_it1 : **m_it2; } - virtual void operator++() { m_first_size > 0 ? (--m_first_size,++(*m_it1)) : ++(*m_it2); } + sample const& operator*() const { return m_first_size > 0 ? *m_it1 : *m_it2; } + void operator++() { if( m_first_size > 0 ) { --m_first_size; ++m_it1; } else ++m_it2; } private: // Data members - iter_ptr m_it1; - iter_ptr m_it2; - data::size_t m_first_size; + dataset1_iter m_it1; + dataset2_iter m_it2; + data::size_t m_first_size; }; -public: - enum { arity = boost::decay<DS1>::type::arity }; - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - // Constructor - join( DS1&& ds1, DS2&& ds2 ) - : m_ds1( std::forward<DS1>( ds1 ) ) - , m_ds2( std::forward<DS2>( ds2 ) ) + //! Constructor + join( DataSet1&& ds1, DataSet2&& ds2 ) + : m_ds1( std::forward<DataSet1>( ds1 ) ) + , m_ds2( std::forward<DataSet2>( ds2 ) ) {} - // Move constructor + //! Move constructor join( join&& j ) - : m_ds1( std::forward<DS1>( j.m_ds1 ) ) - , m_ds2( std::forward<DS2>( j.m_ds2 ) ) + : m_ds1( std::forward<DataSet1>( j.m_ds1 ) ) + , m_ds2( std::forward<DataSet2>( j.m_ds2 ) ) {} -#else - // Constructor - join( DS1 const& ds1, DS2 const& ds2 ) - : m_ds1( ds1 ) - , m_ds2( ds2 ) - {} -#endif - // dataset interface - virtual data::size_t size() const { return m_ds1.size() + m_ds2.size(); } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_ds1.begin(), - m_ds2.begin(), - m_ds1.size() ); } + //! dataset interface + data::size_t size() const { return m_ds1.size() + m_ds2.size(); } + iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin(), m_ds1.size() ); } private: // Data members - DS1 m_ds1; - DS2 m_ds2; + DataSet1 m_ds1; + DataSet2 m_ds2; }; //____________________________________________________________________________// // A joined dataset is a dataset. -template<typename DS1, typename DS2> -struct is_dataset<join<DS1,DS2> > : mpl::true_ {}; +template<typename DataSet1, typename DataSet2> +struct is_dataset<join<DataSet1,DataSet2>> : mpl::true_ {}; //____________________________________________________________________________// namespace result_of { //! Result type of the join operation on datasets. -template<typename DS1Gen, typename DS2Gen> +template<typename DataSet1Gen, typename DataSet2Gen> struct join { - typedef monomorphic::join<typename DS1Gen::type,typename DS2Gen::type> type; + typedef monomorphic::join<typename DataSet1Gen::type,typename DataSet2Gen::type> type; }; } // namespace result_of //____________________________________________________________________________// -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::join<mpl::identity<DS1>,mpl::identity<DS2> > +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value, + result_of::join<mpl::identity<DataSet1>,mpl::identity<DataSet2>> >::type -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES -operator+( DS1&& ds1, DS2&& ds2 ) -{ - return join<DS1,DS2>( std::forward<DS1>( ds1 ), std::forward<DS2>( ds2 ) ); -} -#else -operator+( DS1 const& ds1, DS2 const& ds2 ) +operator+( DataSet1&& ds1, DataSet2&& ds2 ) { - return join<DS1,DS2>( ds1, ds2 ); + return join<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) ); } -#endif //____________________________________________________________________________// -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::join<mpl::identity<DS1>,data::result_of::make<DS2> > +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value, + result_of::join<mpl::identity<DataSet1>,data::result_of::make<DataSet2>> >::type -operator+( DS1&& ds1, DS2&& ds2 ) +operator+( DataSet1&& ds1, DataSet2&& ds2 ) { - return std::forward<DS1>(ds1) + data::make(std::forward<DS2>(ds2)); + return std::forward<DataSet1>( ds1 ) + data::make( std::forward<DataSet2>( ds2 ) ); } -#else -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::join<mpl::identity<DS1>,data::result_of::make<DS2> > ->::type -operator+( DS1 const& ds1, DS2 const& ds2 ) -{ - return ds1 + data::make(ds2); -} -#endif //____________________________________________________________________________// - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::join<data::result_of::make<DS1>,mpl::identity<DS2> > +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value, + result_of::join<data::result_of::make<DataSet1>,mpl::identity<DataSet2>> >::type -operator+( DS1&& ds1, DS2&& ds2 ) +operator+( DataSet1&& ds1, DataSet2&& ds2 ) { - return data::make(std::forward<DS1>(ds1)) + std::forward<DS2>(ds2); + return data::make( std::forward<DataSet1>(ds1) ) + std::forward<DataSet2>( ds2 ); } -#else -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::join<data::result_of::make<DS1>,mpl::identity<DS2> > ->::type -operator+( DS1 const& ds1, DS2 const& ds2 ) -{ - return data::make(ds1) + ds2; -} - -#endif - } // namespace monomorphic - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/monomorphic/singleton.hpp b/boost/test/data/monomorphic/singleton.hpp index 4d305c2546..586487a6d7 100644 --- a/boost/test/data/monomorphic/singleton.hpp +++ b/boost/test/data/monomorphic/singleton.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -31,102 +31,84 @@ namespace monomorphic { /// Models a single element data set template<typename T> -class singleton : public monomorphic::dataset<typename boost::decay<T>::type> { - typedef monomorphic::dataset<typename boost::decay<T>::type> base; - typedef typename base::iter_ptr iter_ptr; +class singleton { +public: + typedef typename boost::decay<T>::type sample; + + enum { arity = 1 }; - struct iterator : public base::iterator { + struct iterator { // Constructor - explicit iterator( singleton<T> const& owner ) + explicit iterator( singleton<T> const* owner ) : m_owner( owner ) {} // forward iterator interface - virtual typename base::data_type const& - operator*() { return m_owner.value(); } - virtual void operator++() {} + sample const& operator*() const { return m_owner->value(); } + void operator++() {} private: - singleton<T> const& m_owner; + singleton<T> const* m_owner; }; -public: - enum { arity = 1 }; - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES //! Constructor - explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {} + explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {} //! Move constructor singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {} -#else - // Constructor - explicit singleton( T const& value ) : m_value( value ) {} -#endif - // Access methods - T const& value() const { return m_value; } + //! Value access method + T const& value() const { return m_value; } - // dataset interface - virtual data::size_t size() const { return 1; } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( *this ); } + //! dataset interface + data::size_t size() const { return 1; } + iterator begin() const { return iterator( this ); } private: // Data members T m_value; }; +//____________________________________________________________________________// + // a singleton is a dataset template<typename T> -struct is_dataset<singleton<T> > : mpl::true_ {}; - -} // namespace monomorphic +struct is_dataset<singleton<T>> : mpl::true_ {}; +//____________________________________________________________________________// +} // namespace monomorphic /// @overload boost::unit_test::data::make() template<typename T> -inline typename BOOST_TEST_ENABLE_IF<!is_forward_iterable<T>::value && - !monomorphic::is_dataset<T>::value && - !boost::is_array< typename boost::remove_reference<T>::type >::value, - monomorphic::singleton<T> +inline typename std::enable_if<!is_forward_iterable<T>::value && + !monomorphic::is_dataset<T>::value && + !boost::is_array<typename boost::remove_reference<T>::type>::value, + monomorphic::singleton<T> >::type -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES make( T&& v ) { return monomorphic::singleton<T>( std::forward<T>( v ) ); } -#else -make( T const& v ) -{ - return monomorphic::singleton<T>( v ); -} -#endif +//____________________________________________________________________________// /// @overload boost::unit_test::data::make -inline monomorphic::singleton<char*> make( char* str ) +inline monomorphic::singleton<char*> +make( char* str ) { -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES return monomorphic::singleton<char*>( std::move(str) ); -#else - return monomorphic::singleton<char*>( str ); -#endif } +//____________________________________________________________________________// /// @overload boost::unit_test::data::make -inline monomorphic::singleton<char const*> make( char const* str ) +inline monomorphic::singleton<char const*> +make( char const* str ) { -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES return monomorphic::singleton<char const*>( std::move(str) ); -#else - return monomorphic::singleton<char const*>( str ); -#endif } - - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/monomorphic/zip.hpp b/boost/test/data/monomorphic/zip.hpp index 3ee91817a9..1c7f46472c 100644 --- a/boost/test/data/monomorphic/zip.hpp +++ b/boost/test/data/monomorphic/zip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -12,12 +12,14 @@ #ifndef BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER #define BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER +// Boost.Test #include <boost/test/data/config.hpp> #if !defined(BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__) -// Boost.Test -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/traits.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + #include <boost/test/detail/suppress_warnings.hpp> @@ -28,14 +30,11 @@ namespace monomorphic { namespace ds_detail { - -//____________________________________________________________________________// - // !! ?? variadic template implementation; use forward_as_tuple? template<typename T1, typename T2> struct zip_traits { typedef std::tuple<T1,T2> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, T2 const& a2) @@ -49,7 +48,7 @@ struct zip_traits { template<typename T1, typename T2,typename T3> struct zip_traits<T1,std::tuple<T2,T3>> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, std::tuple<T2 const&,T3 const&> const& a2) @@ -63,7 +62,7 @@ struct zip_traits<T1,std::tuple<T2,T3>> { template<typename T1, typename T2,typename T3> struct zip_traits<std::tuple<T1,T2>,T3> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(std::tuple<T1 const&,T2 const&> const& a1, T3 const& a2) @@ -72,8 +71,6 @@ struct zip_traits<std::tuple<T1,T2>,T3> { } }; -//____________________________________________________________________________// - } // namespace ds_detail // ************************************************************************** // @@ -84,82 +81,82 @@ struct zip_traits<std::tuple<T1,T2>,T3> { //! //! A zip of two datasets is a dataset whose arity is the sum of the operand datasets arity. The size is given by //! the function creating the instance (see @c operator^ on datasets). -template<typename DS1, typename DS2> -class zip : public monomorphic::dataset<typename ds_detail::zip_traits<typename boost::decay<DS1>::type::data_type, - typename boost::decay<DS2>::type::data_type>::type> { - typedef typename boost::decay<DS1>::type::data_type T1; - typedef typename boost::decay<DS2>::type::data_type T2; +template<typename DataSet1, typename DataSet2> +class zip { + typedef typename boost::decay<DataSet1>::type dataset1_decay; + typedef typename boost::decay<DataSet2>::type dataset2_decay; + + typedef typename dataset1_decay::iterator dataset1_iter; + typedef typename dataset2_decay::iterator dataset2_iter; - typedef typename monomorphic::dataset<T1>::iter_ptr ds1_iter_ptr; - typedef typename monomorphic::dataset<T2>::iter_ptr ds2_iter_ptr; + typedef typename dataset1_decay::sample sample1; + typedef typename dataset2_decay::sample sample2; + +public: + typedef typename ds_detail::zip_traits<sample1,sample2>::type sample; - typedef typename ds_detail::zip_traits<T1,T2>::type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; + enum { arity = dataset1_decay::arity + dataset2_decay::arity }; - struct iterator : public base::iterator { - typedef typename monomorphic::traits<T>::ref_type ref_type; + struct iterator { + typedef typename data::traits<sample>::ref_type ref_type; // Constructor - explicit iterator( ds1_iter_ptr iter1, ds2_iter_ptr iter2 ) - : m_iter1( iter1 ) - , m_iter2( iter2 ) + explicit iterator( dataset1_iter iter1, dataset2_iter iter2 ) + : m_iter1( std::move( iter1 ) ) + , m_iter2( std::move( iter2 ) ) {} // forward iterator interface - virtual ref_type operator*() { return ds_detail::zip_traits<T1,T2>::tuple_merge( **m_iter1, **m_iter2 ); } - virtual void operator++() { ++(*m_iter1); ++(*m_iter2); } + ref_type operator*() const { return ds_detail::zip_traits<sample1,sample2>::tuple_merge( *m_iter1, *m_iter2 ); } + void operator++() { ++m_iter1; ++m_iter2; } private: // Data members - ds1_iter_ptr m_iter1; - ds2_iter_ptr m_iter2; + dataset1_iter m_iter1; + dataset2_iter m_iter2; }; -public: - enum { arity = boost::decay<DS1>::type::arity + boost::decay<DS2>::type::arity }; - //! Constructor //! //! The datasets are moved and not copied. - zip( DS1&& ds1, DS2&& ds2, data::size_t size ) - : m_ds1( std::forward<DS1>( ds1 ) ) - , m_ds2( std::forward<DS2>( ds2 ) ) + zip( DataSet1&& ds1, DataSet2&& ds2, data::size_t size ) + : m_ds1( std::forward<DataSet1>( ds1 ) ) + , m_ds2( std::forward<DataSet2>( ds2 ) ) , m_size( size ) {} //! Move constructor zip( zip&& j ) - : m_ds1( std::forward<DS1>( j.m_ds1 ) ) - , m_ds2( std::forward<DS2>( j.m_ds2 ) ) + : m_ds1( std::forward<DataSet1>( j.m_ds1 ) ) + , m_ds2( std::forward<DataSet2>( j.m_ds2 ) ) , m_size( j.m_size ) {} // dataset interface - virtual data::size_t size() const { return m_size; } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_ds1.begin(), m_ds2.begin() ); } + data::size_t size() const { return m_size; } + iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin() ); } private: // Data members - DS1 m_ds1; - DS2 m_ds2; + DataSet1 m_ds1; + DataSet2 m_ds2; data::size_t m_size; }; //____________________________________________________________________________// //! Zipped datasets results in a dataset. -template<typename DS1, typename DS2> -struct is_dataset<zip<DS1,DS2> > : mpl::true_ {}; +template<typename DataSet1, typename DataSet2> +struct is_dataset<zip<DataSet1,DataSet2>> : mpl::true_ {}; //____________________________________________________________________________// namespace ds_detail { //! Handles the sise of the resulting zipped dataset. -template<typename DS1, typename DS2> +template<typename DataSet1, typename DataSet2> inline data::size_t -zip_size( DS1&& ds1, DS2&& ds2 ) +zip_size( DataSet1&& ds1, DataSet2&& ds2 ) { data::size_t ds1_size = ds1.size(); data::size_t ds2_size = ds2.size(); @@ -190,44 +187,45 @@ struct zip { } // namespace result_of - //____________________________________________________________________________// - //! Overload operator for zip support -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::zip<mpl::identity<DS1>,mpl::identity<DS2>> +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value, + result_of::zip<mpl::identity<DataSet1>,mpl::identity<DataSet2>> >::type -operator^( DS1&& ds1, DS2&& ds2 ) +operator^( DataSet1&& ds1, DataSet2&& ds2 ) { - return zip<DS1,DS2>( std::forward<DS1>( ds1 ), std::forward<DS2>( ds2 ), ds_detail::zip_size( ds1, ds2 ) ); + return zip<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), + std::forward<DataSet2>( ds2 ), + ds_detail::zip_size( ds1, ds2 ) ); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::monomorphic::operator^() -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::zip<mpl::identity<DS1>,data::result_of::make<DS2>> +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value, + result_of::zip<mpl::identity<DataSet1>,data::result_of::make<DataSet2>> >::type -operator^( DS1&& ds1, DS2&& ds2 ) +operator^( DataSet1&& ds1, DataSet2&& ds2 ) { - return std::forward<DS1>(ds1) ^ data::make(std::forward<DS2>(ds2)); + return std::forward<DataSet1>( ds1 ) ^ data::make( std::forward<DataSet2>( ds2 ) ); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::monomorphic::operator^() -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::zip<data::result_of::make<DS1>,mpl::identity<DS2>> +template<typename DataSet1, typename DataSet2> +inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value, + result_of::zip<data::result_of::make<DataSet1>,mpl::identity<DataSet2>> >::type -operator^( DS1&& ds1, DS2&& ds2 ) +operator^( DataSet1&& ds1, DataSet2&& ds2 ) { - return data::make(std::forward<DS1>(ds1)) ^ std::forward<DS2>(ds2); + return data::make( std::forward<DataSet1>( ds1 ) ) ^ std::forward<DataSet2>( ds2 ); } -//____________________________________________________________________________// - } // namespace monomorphic - } // namespace data } // namespace unit_test } // namespace boost |