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)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// Defines single element monomorphic dataset
10 // ***************************************************************************
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
19 #include <boost/test/detail/suppress_warnings.hpp>
21 //____________________________________________________________________________//
26 namespace monomorphic {
28 // ************************************************************************** //
29 // ************** singleton ************** //
30 // ************************************************************************** //
32 /// Models a single element data set
36 typedef typename boost::decay<T>::type sample;
40 static const int arity = 1;
44 explicit iterator( singleton<T> const* owner )
48 // forward iterator interface
49 sample const& operator*() const { return m_owner->value(); }
53 singleton<T> const* m_owner;
57 explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {}
60 singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {}
62 //! Value access method
63 T const& value() const { return m_value; }
66 data::size_t size() const { return 1; }
67 iterator begin() const { return iterator( this ); }
74 //____________________________________________________________________________//
76 // a singleton is a dataset
78 struct is_dataset<singleton<T>> : mpl::true_ {};
80 //____________________________________________________________________________//
82 } // namespace monomorphic
84 /// @overload boost::unit_test::data::make()
86 inline typename std::enable_if<!is_container_forward_iterable<T>::value &&
87 !monomorphic::is_dataset<T>::value &&
88 !boost::is_array<typename boost::remove_reference<T>::type>::value,
89 monomorphic::singleton<T>
93 return monomorphic::singleton<T>( std::forward<T>( v ) );
96 //____________________________________________________________________________//
98 /// @overload boost::unit_test::data::make
99 inline monomorphic::singleton<char*>
102 return monomorphic::singleton<char*>( std::move(str) );
105 //____________________________________________________________________________//
107 /// @overload boost::unit_test::data::make
108 inline monomorphic::singleton<char const*>
109 make( char const* str )
111 return monomorphic::singleton<char const*>( std::move(str) );
115 } // namespace unit_test
118 #include <boost/test/detail/enable_warnings.hpp>
120 #endif // BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER