summaryrefslogtreecommitdiff
path: root/boost/test/data/monomorphic/fwd.hpp
blob: 9ff495543249ad081d751cbfd44086e76c8ee95c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
//  (C) Copyright Gennadiy Rozental 2012-2014.
//  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
/// Forward declares monomorphic datasets interfaces
// ***************************************************************************

#ifndef BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER
#define BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER

// Boost.Test
#include <boost/test/data/config.hpp>
#include <boost/test/data/size.hpp>

#include <boost/test/utils/is_forward_iterable.hpp>


// Boost
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/add_const.hpp>
#else
#include <boost/utility/declval.hpp>
#endif
#include <boost/type_traits/remove_const.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/type_traits/decay.hpp>

#include <boost/test/detail/suppress_warnings.hpp>

//____________________________________________________________________________//

namespace boost {
namespace unit_test {
namespace data {

namespace monomorphic {


#if !defined(BOOST_TEST_DOXYGEN_DOC__)
template<typename T>
struct traits;

template<typename T>
class dataset;

template<typename T>
class singleton;

template<typename C>
class collection;

template<typename T>
class array;
#endif

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
#  define BOOST_TEST_ENABLE_IF std::enable_if
#else
#  define BOOST_TEST_ENABLE_IF boost::enable_if_c
#endif

// ************************************************************************** //
// **************            monomorphic::is_dataset           ************** //
// ************************************************************************** //

//! Helper metafunction indicating if the specified type is a dataset.
template<typename DataSet>
struct is_dataset : mpl::false_ {};

//! A reference to a dataset is a dataset
template<typename DataSet>
struct is_dataset<DataSet&> : is_dataset<DataSet> {};

//! A const dataset is a dataset
template<typename DataSet>
struct is_dataset<DataSet const> : is_dataset<DataSet> {};

//____________________________________________________________________________//

} // namespace monomorphic

// ************************************************************************** //
// **************                  data::make                  ************** //
// ************************************************************************** //

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES


//! @brief Creates a dataset from a value, a collection or an array
//!
//! This function has several overloads:
//! @code
//! // returns ds if ds is already a dataset
//! template <typename DataSet> DataSet make(DataSet&& ds); 
//!
//! // creates a singleton dataset, for non forward iterable and non dataset type T
//! // (a C string is not considered as a sequence).
//! template <typename T> monomorphic::singleton<T> make(T&& v); 
//! monomorphic::singleton<char*> make( char* str );
//! monomorphic::singleton<char const*> make( char const* str );
//!
//! // creates a collection dataset, for forward iterable and non dataset type C
//! template <typename C> monomorphic::collection<C> make(C && c);
//!
//! // creates an array dataset
//! template<typename T, std::size_t size> monomorphic::array<T> make( T (&a)[size] );
//! @endcode
template<typename DataSet>
inline typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value,DataSet>::type
make(DataSet&& ds)
{
    return std::forward<DataSet>( ds );
}


// warning: doxygen is apparently unable to handle @overload from different files, so if the overloads
// below are not declared with @overload in THIS file, they do not appear in the documentation.

// fwrd declaration for singletons
//! @overload boost::unit_test::data::make()
template<typename T>
inline typename BOOST_TEST_ENABLE_IF<!is_forward_iterable<T>::value && 
                                     !monomorphic::is_dataset<T>::value &&
                                     !boost::is_array< typename boost::remove_reference<T>::type >::value, 
                                     monomorphic::singleton<T> >::type
make( T&& v );


//! @overload boost::unit_test::data::make()
template<typename C>
inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, 
                                     monomorphic::collection<C> >::type
make( C&& c );


#else  // !BOOST_NO_CXX11_RVALUE_REFERENCES

//! @overload boost::unit_test:data::make()
template<typename DataSet>
inline typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value,DataSet const&>::type
make(DataSet const& ds)
{
    return ds;
}


// fwrd declaration for singletons
#if !(defined(BOOST_MSVC) && (BOOST_MSVC < 1600))
//! @overload boost::unit_test::data::make()
template<typename T>
inline typename BOOST_TEST_ENABLE_IF<!is_forward_iterable<T>::value && 
                                     !monomorphic::is_dataset<T>::value &&
                                     !boost::is_array< typename boost::remove_reference<T>::type >::value, 
                                     monomorphic::singleton<T> >::type
make( T const& v );
#endif


// fwrd declaration for collections
//! @overload boost::unit_test::data::make()
template<typename C>
inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, 
                                     monomorphic::collection<C> >::type
make( C const& c );

//____________________________________________________________________________//



#endif // !BOOST_NO_CXX11_RVALUE_REFERENCES




// fwrd declarations
//! @overload boost::unit_test::data::make()
template<typename T, std::size_t size>
inline monomorphic::array< typename boost::remove_const<T>::type >
make( T (&a)[size] );

// apparently some compilers (eg clang-3.4 on linux) have trouble understanding
// the previous line for T being const
//! @overload boost::unit_test::data::make()
template<typename T, std::size_t size>
inline monomorphic::array< typename boost::remove_const<T>::type >
make( T const (&)[size] );

template<typename T, std::size_t size>
inline monomorphic::array< typename boost::remove_const<T>::type >
make( T a[size] );



//! @overload boost::unit_test::data::make()
inline monomorphic::singleton<char*>
make( char* str );

//! @overload boost::unit_test::data::make()
inline monomorphic::singleton<char const*>
make( char const* str );



//____________________________________________________________________________//



namespace result_of {

#ifndef BOOST_NO_CXX11_DECLTYPE
//! Result of the make call.
template<typename DataSet>
struct make
{
    typedef decltype(data::make(boost::declval<DataSet>())) type;
};
#else

// explicit specialisation, cumbersome

template <typename DataSet, typename Enable = void>
struct make;

template <typename DataSet>
struct make<
         DataSet const&, 
         typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value>::type
         >
{
    typedef DataSet const& type;
};

template <typename T>
struct make<
         T, 
         typename BOOST_TEST_ENABLE_IF< (!is_forward_iterable<T>::value && 
                                         !monomorphic::is_dataset<T>::value &&
                                         !boost::is_array< typename boost::remove_reference<T>::type >::value)
                                      >::type
         >
{
    typedef monomorphic::singleton<T> type;
};

template <typename C>  
struct make<
         C, 
         typename BOOST_TEST_ENABLE_IF< is_forward_iterable<C>::value>::type
         >
{
    typedef monomorphic::collection<C> type;
};

#if 1 
template <typename T, std::size_t size>  
struct make<T [size]>
{
    typedef monomorphic::array<typename boost::remove_const<T>::type> type;
};
#endif

template <typename T, std::size_t size>  
struct make<T (&)[size]>
{
    typedef monomorphic::array<typename boost::remove_const<T>::type> type;
};

template <typename T, std::size_t size>  
struct make<T const (&)[size]>
{
    typedef monomorphic::array<typename boost::remove_const<T>::type> type;
};

template <>  
struct make<char*>
{
    typedef monomorphic::singleton<char*> type;
};

template <>  
struct make<char const*>
{
    typedef monomorphic::singleton<char const*> type;
};

#endif // BOOST_NO_CXX11_DECLTYPE


} // namespace result_of




//____________________________________________________________________________//

} // namespace data
} // namespace unit_test
} // namespace boost





#include <boost/test/detail/enable_warnings.hpp>

#endif // BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER