fwd.hpp 6.9 KB

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