array.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 C type arrays
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_DATA_MONOMORPHIC_ARRAY_HPP_121411GER
  11. #define BOOST_TEST_DATA_MONOMORPHIC_ARRAY_HPP_121411GER
  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. // ************** array ************** //
  23. // ************************************************************************** //
  24. /// Dataset view of a C array
  25. template<typename T>
  26. class array {
  27. public:
  28. typedef T sample;
  29. enum { arity = 1 };
  30. typedef T const* iterator;
  31. // Constructor
  32. array( T const* arr_, std::size_t size_ )
  33. : m_arr( arr_ )
  34. , m_size( size_ )
  35. {}
  36. // dataset interface
  37. data::size_t size() const { return m_size; }
  38. iterator begin() const { return m_arr; }
  39. private:
  40. // Data members
  41. T const* m_arr;
  42. std::size_t m_size;
  43. };
  44. //____________________________________________________________________________//
  45. //! An array dataset is a dataset
  46. template<typename T>
  47. struct is_dataset<array<T>> : mpl::true_ {};
  48. } // namespace monomorphic
  49. //____________________________________________________________________________//
  50. //! @overload boost::unit_test::data::make()
  51. template<typename T, std::size_t size>
  52. inline monomorphic::array<typename boost::remove_const<T>::type>
  53. make( T (&a)[size] )
  54. {
  55. return monomorphic::array<typename boost::remove_const<T>::type>( a, size );
  56. }
  57. } // namespace data
  58. } // namespace unit_test
  59. } // namespace boost
  60. #include <boost/test/detail/enable_warnings.hpp>
  61. #endif // BOOST_TEST_DATA_MONOMORPHIC_ARRAY_HPP_121411GER