Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/test/data/monomorphic/delayed.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 Raffi Enficiaud 2018.
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 a lazy/delayed dataset store
0010 // ***************************************************************************
0011 
0012 #ifndef BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER
0013 #define BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER
0014 
0015 // Boost.Test
0016 #include <boost/test/data/config.hpp>
0017 #include <boost/test/data/monomorphic/fwd.hpp>
0018 #include <boost/test/data/index_sequence.hpp>
0019 
0020 #include <boost/core/ref.hpp>
0021 
0022 #include <algorithm>
0023 #include <memory>
0024 
0025 #include <boost/test/detail/suppress_warnings.hpp>
0026 
0027 //____________________________________________________________________________//
0028 
0029 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
0030     !defined(BOOST_NO_CXX11_HDR_TUPLE)
0031 
0032 namespace boost {
0033 namespace unit_test {
0034 namespace data {
0035 namespace monomorphic {
0036 
0037 // ************************************************************************** //
0038 // **************               delayed_dataset                ************** //
0039 // ************************************************************************** //
0040 
0041 
0042 /// Delayed dataset
0043 ///
0044 /// This dataset holds another dataset that is instanciated on demand. It is
0045 /// constructed with the @c data::make_delayed<dataset_t>(arg1,....) instead of the
0046 /// @c data::make.
0047 template <class dataset_t, class ...Args>
0048 class delayed_dataset
0049 {
0050 public:
0051     static const int arity = dataset_t::arity;
0052     using iterator = decltype(std::declval<dataset_t>().begin());
0053 
0054     delayed_dataset(Args... args)
0055     : m_args(std::make_tuple(std::forward<Args>(args)...))
0056     {}
0057 
0058     // Mostly for VS2013
0059     delayed_dataset(delayed_dataset&& b) 
0060     : m_args(std::move(b.m_args))
0061     , m_dataset(std::move(b.m_dataset))
0062     {}
0063 
0064     boost::unit_test::data::size_t size() const {
0065         return this->get().size();
0066     }
0067 
0068     // iterator
0069     iterator begin() const {
0070         return this->get().begin();
0071     }
0072   
0073 private:
0074 
0075   dataset_t& get() const {
0076       if(!m_dataset) {
0077           m_dataset = create(boost::unit_test::data::index_sequence_for<Args...>());
0078       }
0079       return *m_dataset;
0080   }
0081 
0082   template<std::size_t... I>
0083   std::unique_ptr<dataset_t>
0084   create(boost::unit_test::data::index_sequence<I...>) const
0085   {
0086       return std::unique_ptr<dataset_t>{new dataset_t(std::get<I>(m_args)...)};
0087   }
0088 
0089   std::tuple<typename std::decay<Args>::type...> m_args;
0090   mutable std::unique_ptr<dataset_t> m_dataset;
0091 };
0092 
0093 //____________________________________________________________________________//
0094 
0095 //! A lazy/delayed dataset is a dataset.
0096 template <class dataset_t, class ...Args>
0097 struct is_dataset< delayed_dataset<dataset_t, Args...> > : boost::mpl::true_ {};
0098 
0099 //____________________________________________________________________________//
0100 
0101 } // namespace monomorphic
0102 
0103 
0104 //! Delayed dataset instanciation
0105 template<class dataset_t, class ...Args>
0106 inline typename std::enable_if<
0107   monomorphic::is_dataset< dataset_t >::value,
0108   monomorphic::delayed_dataset<dataset_t, Args...>
0109 >::type
0110 make_delayed(Args... args)
0111 {
0112     return monomorphic::delayed_dataset<dataset_t, Args...>( std::forward<Args>(args)... );
0113 }
0114 
0115 
0116 } // namespace data
0117 } // namespace unit_test
0118 } // namespace boost
0119 
0120 #endif
0121 
0122 #include <boost/test/detail/enable_warnings.hpp>
0123 
0124 #endif // BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER