1 // (C) Copyright Gennadiy Rozental 2001.
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 monomorphic dataset based on C++11 initializer_list template
10 // ***************************************************************************
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
19 #include <boost/core/ignore_unused.hpp>
23 #include <boost/test/detail/suppress_warnings.hpp>
25 //____________________________________________________________________________//
30 namespace monomorphic {
32 // ************************************************************************** //
33 // ************** initializer_list ************** //
34 // ************************************************************************** //
36 /// Dataset view from an initializer_list or variadic template arguments
38 /// The data should be stored in the dataset, and since the elements
39 /// are passed by an @c std::initializer_list , it implies a copy of
44 static const int arity = 1;
46 typedef typename std::vector<T>::const_iterator iterator;
48 //! Constructor copies content of initializer_list
49 init_list( std::initializer_list<T> il )
53 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
54 !defined(BOOST_TEST_ERRONEOUS_INIT_LIST)
55 //! Variadic template initialization
56 template <class ...Args>
57 init_list( Args&& ... args ) {
58 int dummy[] = { 0, (m_data.emplace_back(std::forward<Args&&>(args)), 0)... };
59 boost::ignore_unused(dummy);
64 data::size_t size() const { return m_data.size(); }
65 iterator begin() const { return m_data.begin(); }
69 std::vector<T> m_data;
72 //! Specialization of init_list for type bool
74 class init_list<bool> {
78 static const int arity = 1;
80 //! Constructor copies content of initializer_list
81 init_list( std::initializer_list<bool>&& il )
82 : m_data( std::forward<std::initializer_list<bool>>( il ) )
85 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
86 !defined(BOOST_TEST_ERRONEOUS_INIT_LIST)
87 //! Variadic template initialization
88 template <class ...Args>
89 init_list( Args&& ... args ) : m_data{ args... }
93 struct non_proxy_iterator {
94 std::vector<bool>::const_iterator iterator;
95 non_proxy_iterator(std::vector<bool>::const_iterator &&it)
96 : iterator(std::forward<std::vector<bool>::const_iterator>(it))
99 bool operator*() const {
103 non_proxy_iterator& operator++() {
109 typedef non_proxy_iterator iterator;
111 //! dataset interface
112 data::size_t size() const { return m_data.size(); }
113 iterator begin() const { return m_data.begin(); }
117 std::vector<bool> m_data;
120 //____________________________________________________________________________//
122 //! An array dataset is a dataset
124 struct is_dataset<init_list<T>> : mpl::true_ {};
126 } // namespace monomorphic
128 //____________________________________________________________________________//
130 //! @overload boost::unit_test::data::make()
132 inline monomorphic::init_list<T>
133 make( std::initializer_list<T>&& il )
135 return monomorphic::init_list<T>( std::forward<std::initializer_list<T>>( il ) );
138 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
139 !defined(BOOST_TEST_ERRONEOUS_INIT_LIST)
140 template<class T, class ...Args>
141 inline typename std::enable_if<
142 !monomorphic::has_dataset<T, Args...>::value,
143 monomorphic::init_list<T>
145 make( T&& arg0, Args&&... args )
147 return monomorphic::init_list<T>( std::forward<T>(arg0), std::forward<Args>( args )... );
153 } // namespace unit_test
156 #include <boost/test/detail/enable_warnings.hpp>
158 #endif // BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER