collection.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. ///Defines monomorphic dataset based on forward iterable sequence
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_DATA_MONOMORPHIC_COLLECTION_HPP_102211GER
  11. #define BOOST_TEST_DATA_MONOMORPHIC_COLLECTION_HPP_102211GER
  12. // Boost.Test
  13. #include <boost/test/data/config.hpp>
  14. #include <boost/test/data/monomorphic/fwd.hpp>
  15. #include <boost/test/detail/suppress_warnings.hpp>
  16. //____________________________________________________________________________//
  17. namespace boost {
  18. namespace unit_test {
  19. namespace data {
  20. namespace monomorphic {
  21. // ************************************************************************** //
  22. // ************** collection ************** //
  23. // ************************************************************************** //
  24. //!@brief Dataset from a forward iterable container (collection)
  25. //!
  26. //! This dataset is applicable to any container implementing a forward iterator. Note that
  27. //! container with one element will be considered as singletons.
  28. //! This dataset is constructible with the @ref boost::unit_test::data::make function.
  29. template<typename C>
  30. class collection {
  31. typedef typename boost::decay<C>::type col_type;
  32. public:
  33. typedef typename col_type::value_type sample;
  34. enum { arity = 1 };
  35. typedef typename col_type::const_iterator iterator;
  36. //! Constructor consumed a temporary collection or stores a reference
  37. explicit collection( C&& col ) : m_col( std::forward<C>(col) ) {}
  38. //! Move constructor
  39. collection( collection&& c ) : m_col( std::forward<C>( c.m_col ) ) {}
  40. //! Returns the underlying collection
  41. C const& col() const { return m_col; }
  42. //! dataset interface
  43. data::size_t size() const { return m_col.size(); }
  44. iterator begin() const { return m_col.begin(); }
  45. private:
  46. // Data members
  47. C m_col;
  48. };
  49. //____________________________________________________________________________//
  50. //! A collection from a forward iterable container is a dataset.
  51. template<typename C>
  52. struct is_dataset<collection<C>> : mpl::true_ {};
  53. } // namespace monomorphic
  54. //____________________________________________________________________________//
  55. //! @overload boost::unit_test::data::make()
  56. template<typename C>
  57. inline typename std::enable_if<is_container_forward_iterable<C>::value,monomorphic::collection<C>>::type
  58. make( C&& c )
  59. {
  60. return monomorphic::collection<C>( std::forward<C>(c) );
  61. }
  62. } // namespace data
  63. } // namespace unit_test
  64. } // namespace boost
  65. #include <boost/test/detail/enable_warnings.hpp>
  66. #endif // BOOST_TEST_DATA_MONOMORPHIC_COLLECTION_HPP_102211GER