// (C) Copyright Raffi Enficiaud 2018. // 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 a lazy/delayed dataset store // *************************************************************************** #ifndef BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER #define BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER // Boost.Test #include #include #include #include #include #include #include //____________________________________________________________________________// #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ !defined(BOOST_NO_CXX11_HDR_TUPLE) namespace boost { namespace unit_test { namespace data { namespace monomorphic { // ************************************************************************** // // ************** delayed_dataset ************** // // ************************************************************************** // /// Delayed dataset /// /// This dataset holds another dataset that is instanciated on demand. It is /// constructed with the @c data::make_delayed(arg1,....) instead of the /// @c data::make. template class delayed_dataset { public: enum { arity = dataset_t::arity }; using iterator = decltype(std::declval().begin()); delayed_dataset(Args... args) : m_args(std::make_tuple(std::forward(args)...)) {} // Mostly for VS2013 delayed_dataset(delayed_dataset&& b) : m_args(std::move(b.m_args)) , m_dataset(std::move(b.m_dataset)) {} boost::unit_test::data::size_t size() const { return this->get().size(); } // iterator iterator begin() const { return this->get().begin(); } private: dataset_t& get() const { if(!m_dataset) { m_dataset = create(boost::unit_test::data::index_sequence_for()); } return *m_dataset; } template std::unique_ptr create(boost::unit_test::data::index_sequence) const { return std::unique_ptr{new dataset_t(std::get(m_args)...)}; } std::tuple::type...> m_args; mutable std::unique_ptr m_dataset; }; //____________________________________________________________________________// //! A lazy/delayed dataset is a dataset. template struct is_dataset< delayed_dataset > : boost::mpl::true_ {}; //____________________________________________________________________________// } // namespace monomorphic //! Delayed dataset instanciation template inline typename std::enable_if< monomorphic::is_dataset< dataset_t >::value, monomorphic::delayed_dataset >::type make_delayed(Args... args) { return monomorphic::delayed_dataset( std::forward(args)... ); } } // namespace data } // namespace unit_test } // namespace boost #endif #include #endif // BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER