1 // (C) Copyright Raffi Enficiaud 2018.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// Defines a lazy/delayed dataset store
10 // ***************************************************************************
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
18 #include <boost/test/data/index_sequence.hpp>
20 #include <boost/core/ref.hpp>
25 #include <boost/test/detail/suppress_warnings.hpp>
27 //____________________________________________________________________________//
29 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
30 !defined(BOOST_NO_CXX11_HDR_TUPLE)
35 namespace monomorphic {
37 // ************************************************************************** //
38 // ************** delayed_dataset ************** //
39 // ************************************************************************** //
44 /// This dataset holds another dataset that is instanciated on demand. It is
45 /// constructed with the @c data::make_delayed<dataset_t>(arg1,....) instead of the
47 template <class dataset_t, class ...Args>
51 enum { arity = dataset_t::arity };
52 using iterator = decltype(std::declval<dataset_t>().begin());
54 delayed_dataset(Args... args)
55 : m_args(std::make_tuple(std::forward<Args>(args)...))
59 delayed_dataset(delayed_dataset&& b)
60 : m_args(std::move(b.m_args))
61 , m_dataset(std::move(b.m_dataset))
64 boost::unit_test::data::size_t size() const {
65 return this->get().size();
69 iterator begin() const {
70 return this->get().begin();
75 dataset_t& get() const {
77 m_dataset = create(boost::unit_test::data::index_sequence_for<Args...>());
82 template<std::size_t... I>
83 std::unique_ptr<dataset_t>
84 create(boost::unit_test::data::index_sequence<I...>) const
86 return std::unique_ptr<dataset_t>{new dataset_t(std::get<I>(m_args)...)};
89 std::tuple<typename std::decay<Args>::type...> m_args;
90 mutable std::unique_ptr<dataset_t> m_dataset;
93 //____________________________________________________________________________//
95 //! A lazy/delayed dataset is a dataset.
96 template <class dataset_t, class ...Args>
97 struct is_dataset< delayed_dataset<dataset_t, Args...> > : boost::mpl::true_ {};
99 //____________________________________________________________________________//
101 } // namespace monomorphic
104 //! Delayed dataset instanciation
105 template<class dataset_t, class ...Args>
106 inline typename std::enable_if<
107 monomorphic::is_dataset< dataset_t >::value,
108 monomorphic::delayed_dataset<dataset_t, Args...>
110 make_delayed(Args... args)
112 return monomorphic::delayed_dataset<dataset_t, Args...>( std::forward<Args>(args)... );
117 } // namespace unit_test
122 #include <boost/test/detail/enable_warnings.hpp>
124 #endif // BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER