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) |
5 | |
6 | // See http://www.boost.org/libs/test for the library home page. |
7 | // |
8 | /// @file |
9 | /// Forward declares monomorphic datasets interfaces |
10 | // *************************************************************************** |
11 | |
12 | #ifndef BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER |
13 | #define BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER |
14 | |
15 | // Boost.Test |
16 | #include <boost/test/data/config.hpp> |
17 | #include <boost/test/data/size.hpp> |
18 | |
19 | #include <boost/test/utils/is_forward_iterable.hpp> |
20 | |
21 | // Boost |
22 | #include <boost/type_traits/remove_const.hpp> |
23 | #include <boost/type_traits/remove_reference.hpp> |
24 | #include <boost/type_traits/is_array.hpp> |
25 | #include <boost/mpl/bool.hpp> |
26 | |
27 | // STL |
28 | #include <tuple> |
29 | |
30 | #include <boost/test/detail/suppress_warnings.hpp> |
31 | |
32 | // STL |
33 | #include <initializer_list> |
34 | |
35 | //____________________________________________________________________________// |
36 | |
37 | namespace boost { |
38 | namespace unit_test { |
39 | namespace data { |
40 | |
41 | namespace monomorphic { |
42 | |
43 | |
44 | #if !defined(BOOST_TEST_DOXYGEN_DOC__) |
45 | |
46 | template<typename T> |
47 | class singleton; |
48 | |
49 | template<typename C> |
50 | class collection; |
51 | |
52 | template<typename T> |
53 | class array; |
54 | |
55 | template<typename T> |
56 | class init_list; |
57 | |
58 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ |
59 | !defined(BOOST_NO_CXX11_HDR_TUPLE) |
60 | template<class dataset_t, class ...Args> |
61 | class delayed_dataset; |
62 | #endif |
63 | |
64 | #endif |
65 | |
66 | // ************************************************************************** // |
67 | // ************** monomorphic::is_dataset ************** // |
68 | // ************************************************************************** // |
69 | |
70 | //! Helper metafunction indicating if the specified type is a dataset. |
71 | template<typename DataSet> |
72 | struct is_dataset : mpl::false_ {}; |
73 | |
74 | //____________________________________________________________________________// |
75 | |
76 | //! A reference to a dataset is a dataset |
77 | template<typename DataSet> |
78 | struct is_dataset<DataSet&> : is_dataset<DataSet> {}; |
79 | template<typename DataSet> |
80 | struct is_dataset<DataSet&&> : is_dataset<DataSet> {}; |
81 | |
82 | //____________________________________________________________________________// |
83 | |
84 | //! A const dataset is a dataset |
85 | template<typename DataSet> |
86 | struct is_dataset<DataSet const> : is_dataset<DataSet> {}; |
87 | |
88 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) |
89 | |
90 | //! Helper to check if a list of types contains a dataset |
91 | template<class DataSet, class...> |
92 | struct has_dataset : is_dataset<DataSet> {}; |
93 | |
94 | template<class DataSet0, class DataSet1, class... DataSetTT> |
95 | struct has_dataset<DataSet0, DataSet1, DataSetTT...> |
96 | : std::integral_constant<bool, is_dataset<DataSet0>::value || has_dataset<DataSet1, DataSetTT...>::value> |
97 | {}; |
98 | #endif |
99 | |
100 | } // namespace monomorphic |
101 | |
102 | // ************************************************************************** // |
103 | // ************** data::make ************** // |
104 | // ************************************************************************** // |
105 | |
106 | //! @brief Creates a dataset from a value, a collection or an array |
107 | //! |
108 | //! This function has several overloads: |
109 | //! @code |
110 | //! // returns ds if ds is already a dataset |
111 | //! template <typename DataSet> DataSet make(DataSet&& ds); |
112 | //! |
113 | //! // creates a singleton dataset, for non forward iterable and non dataset type T |
114 | //! // (a C string is not considered as a sequence). |
115 | //! template <typename T> monomorphic::singleton<T> make(T&& v); |
116 | //! monomorphic::singleton<char*> make( char* str ); |
117 | //! monomorphic::singleton<char const*> make( char const* str ); |
118 | //! |
119 | //! // creates a collection dataset, for forward iterable and non dataset type C |
120 | //! template <typename C> monomorphic::collection<C> make(C && c); |
121 | //! |
122 | //! // creates an array dataset |
123 | //! template<typename T, std::size_t size> monomorphic::array<T> make( T (&a)[size] ); |
124 | //! @endcode |
125 | template<typename DataSet> |
126 | inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,DataSet>::type |
127 | make(DataSet&& ds) |
128 | { |
129 | return std::forward<DataSet>( ds ); |
130 | } |
131 | |
132 | //____________________________________________________________________________// |
133 | |
134 | // warning: doxygen is apparently unable to handle @overload from different files, so if the overloads |
135 | // below are not declared with @overload in THIS file, they do not appear in the documentation. |
136 | |
137 | //! @overload boost::unit_test::data::make() |
138 | template<typename T> |
139 | inline typename std::enable_if<!is_container_forward_iterable<T>::value && |
140 | !monomorphic::is_dataset<T>::value && |
141 | !is_array<typename remove_reference<T>::type>::value, |
142 | monomorphic::singleton<T>>::type |
143 | make( T&& v ); |
144 | |
145 | //____________________________________________________________________________// |
146 | |
147 | //! @overload boost::unit_test::data::make() |
148 | template<typename C> |
149 | inline typename std::enable_if<is_container_forward_iterable<C>::value,monomorphic::collection<C>>::type |
150 | make( C&& c ); |
151 | |
152 | //____________________________________________________________________________// |
153 | |
154 | //! @overload boost::unit_test::data::make() |
155 | template<typename T, std::size_t size> |
156 | inline monomorphic::array< typename boost::remove_const<T>::type > |
157 | make( T (&a)[size] ); |
158 | |
159 | //____________________________________________________________________________// |
160 | |
161 | //! @overload boost::unit_test::data::make() |
162 | inline monomorphic::singleton<char*> |
163 | make( char* str ); |
164 | |
165 | //____________________________________________________________________________// |
166 | |
167 | //! @overload boost::unit_test::data::make() |
168 | inline monomorphic::singleton<char const*> |
169 | make( char const* str ); |
170 | |
171 | //____________________________________________________________________________// |
172 | |
173 | //! @overload boost::unit_test::data::make() |
174 | template<typename T> |
175 | inline monomorphic::init_list<T> |
176 | make( std::initializer_list<T>&& ); |
177 | |
178 | //____________________________________________________________________________// |
179 | |
180 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ |
181 | !defined(BOOST_TEST_ERRONEOUS_INIT_LIST) |
182 | //! @overload boost::unit_test::data::make() |
183 | template<class T, class ...Args> |
184 | inline typename std::enable_if< |
185 | !monomorphic::has_dataset<T, Args...>::value, |
186 | monomorphic::init_list<T> |
187 | >::type |
188 | make( T&& arg0, Args&&... args ); |
189 | #endif |
190 | |
191 | //____________________________________________________________________________// |
192 | |
193 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ |
194 | !defined(BOOST_NO_CXX11_HDR_TUPLE) |
195 | template<class dataset_t, class ...Args> |
196 | inline typename std::enable_if< |
197 | monomorphic::is_dataset< dataset_t >::value, |
198 | monomorphic::delayed_dataset<dataset_t, Args...> |
199 | >::type |
200 | make_delayed(Args... args); |
201 | #endif |
202 | |
203 | //____________________________________________________________________________// |
204 | |
205 | namespace result_of { |
206 | |
207 | //! Result of the make call. |
208 | template<typename DataSet> |
209 | struct make { |
210 | typedef decltype( data::make( declval<DataSet>() ) ) type; |
211 | }; |
212 | |
213 | } // namespace result_of |
214 | |
215 | } // namespace data |
216 | } // namespace unit_test |
217 | } // namespace boost |
218 | |
219 | #include <boost/test/detail/enable_warnings.hpp> |
220 | |
221 | #endif // BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER |
222 | |
223 | |