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;
42 explicit iterator( singleton<T> const* owner )
46 // forward iterator interface
47 sample const& operator*() const { return m_owner->value(); }
51 singleton<T> const* m_owner;
55 explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {}
58 singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {}
60 //! Value access method
61 T const& value() const { return m_value; }
64 data::size_t size() const { return 1; }
65 iterator begin() const { return iterator( this ); }
72 //____________________________________________________________________________//
74 // a singleton is a dataset
76 struct is_dataset<singleton<T>> : mpl::true_ {};
78 //____________________________________________________________________________//
80 } // namespace monomorphic
82 /// @overload boost::unit_test::data::make()
84 inline typename std::enable_if<!is_container_forward_iterable<T>::value &&
85 !monomorphic::is_dataset<T>::value &&
86 !boost::is_array<typename boost::remove_reference<T>::type>::value,
87 monomorphic::singleton<T>
91 return monomorphic::singleton<T>( std::forward<T>( v ) );
94 //____________________________________________________________________________//
96 /// @overload boost::unit_test::data::make
97 inline monomorphic::singleton<char*>
100 return monomorphic::singleton<char*>( std::move(str) );
103 //____________________________________________________________________________//
105 /// @overload boost::unit_test::data::make
106 inline monomorphic::singleton<char const*>
107 make( char const* str )
109 return monomorphic::singleton<char const*>( std::move(str) );
113 } // namespace unit_test
116 #include <boost/test/detail/enable_warnings.hpp>
118 #endif // BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER