]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/data/monomorphic/delayed.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / test / data / monomorphic / delayed.hpp
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)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 /// @file
9 /// Defines a lazy/delayed dataset store
10 // ***************************************************************************
11
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER
14
15 // Boost.Test
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
18 #include <boost/test/data/index_sequence.hpp>
19
20 #include <boost/core/ref.hpp>
21
22 #include <algorithm>
23 #include <memory>
24
25 #include <boost/test/detail/suppress_warnings.hpp>
26
27 //____________________________________________________________________________//
28
29 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
30 !defined(BOOST_NO_CXX11_HDR_TUPLE)
31
32 namespace boost {
33 namespace unit_test {
34 namespace data {
35 namespace monomorphic {
36
37 // ************************************************************************** //
38 // ************** delayed_dataset ************** //
39 // ************************************************************************** //
40
41
42 /// Delayed dataset
43 ///
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
46 /// @c data::make.
47 template <class dataset_t, class ...Args>
48 class delayed_dataset
49 {
50 public:
51 enum { arity = dataset_t::arity };
52 using iterator = decltype(std::declval<dataset_t>().begin());
53
54 delayed_dataset(Args... args)
55 : m_args(std::make_tuple(std::forward<Args>(args)...))
56 {}
57
58 // Mostly for VS2013
59 delayed_dataset(delayed_dataset&& b)
60 : m_args(std::move(b.m_args))
61 , m_dataset(std::move(b.m_dataset))
62 {}
63
64 boost::unit_test::data::size_t size() const {
65 return this->get().size();
66 }
67
68 // iterator
69 iterator begin() const {
70 return this->get().begin();
71 }
72
73 private:
74
75 dataset_t& get() const {
76 if(!m_dataset) {
77 m_dataset = create(boost::unit_test::data::index_sequence_for<Args...>());
78 }
79 return *m_dataset;
80 }
81
82 template<std::size_t... I>
83 std::unique_ptr<dataset_t>
84 create(boost::unit_test::data::index_sequence<I...>) const
85 {
86 return std::unique_ptr<dataset_t>{new dataset_t(std::get<I>(m_args)...)};
87 }
88
89 std::tuple<typename std::decay<Args>::type...> m_args;
90 mutable std::unique_ptr<dataset_t> m_dataset;
91 };
92
93 //____________________________________________________________________________//
94
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_ {};
98
99 //____________________________________________________________________________//
100
101 } // namespace monomorphic
102
103
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...>
109 >::type
110 make_delayed(Args... args)
111 {
112 return monomorphic::delayed_dataset<dataset_t, Args...>( std::forward<Args>(args)... );
113 }
114
115
116 } // namespace data
117 } // namespace unit_test
118 } // namespace boost
119
120 #endif
121
122 #include <boost/test/detail/enable_warnings.hpp>
123
124 #endif // BOOST_TEST_DATA_MONOMORPHIC_DELAYED_HPP_062018GER