]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/include/boost/test/data/monomorphic/singleton.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / include / boost / test / data / monomorphic / singleton.hpp
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
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 /// @file
9 /// Defines single element monomorphic dataset
10 // ***************************************************************************
11
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
14
15 // Boost.Test
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
18
19 #include <boost/test/detail/suppress_warnings.hpp>
20
21 //____________________________________________________________________________//
22
23 namespace boost {
24 namespace unit_test {
25 namespace data {
26 namespace monomorphic {
27
28 // ************************************************************************** //
29 // ************** singleton ************** //
30 // ************************************************************************** //
31
32 /// Models a single element data set
33 template<typename T>
34 class singleton {
35 public:
36 typedef typename boost::decay<T>::type sample;
37
38 enum { arity = 1 };
39
40 struct iterator {
41 // Constructor
42 explicit iterator( singleton<T> const* owner )
43 : m_owner( owner )
44 {}
45
46 // forward iterator interface
47 sample const& operator*() const { return m_owner->value(); }
48 void operator++() {}
49
50 private:
51 singleton<T> const* m_owner;
52 };
53
54 //! Constructor
55 explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {}
56
57 //! Move constructor
58 singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {}
59
60 //! Value access method
61 T const& value() const { return m_value; }
62
63 //! dataset interface
64 data::size_t size() const { return 1; }
65 iterator begin() const { return iterator( this ); }
66
67 private:
68 // Data members
69 T m_value;
70 };
71
72 //____________________________________________________________________________//
73
74 // a singleton is a dataset
75 template<typename T>
76 struct is_dataset<singleton<T>> : mpl::true_ {};
77
78 //____________________________________________________________________________//
79
80 } // namespace monomorphic
81
82 /// @overload boost::unit_test::data::make()
83 template<typename T>
84 inline typename std::enable_if<!is_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>
88 >::type
89 make( T&& v )
90 {
91 return monomorphic::singleton<T>( std::forward<T>( v ) );
92 }
93
94 //____________________________________________________________________________//
95
96 /// @overload boost::unit_test::data::make
97 inline monomorphic::singleton<char*>
98 make( char* str )
99 {
100 return monomorphic::singleton<char*>( std::move(str) );
101 }
102
103 //____________________________________________________________________________//
104
105 /// @overload boost::unit_test::data::make
106 inline monomorphic::singleton<char const*>
107 make( char const* str )
108 {
109 return monomorphic::singleton<char const*>( std::move(str) );
110 }
111
112 } // namespace data
113 } // namespace unit_test
114 } // namespace boost
115
116 #include <boost/test/detail/enable_warnings.hpp>
117
118 #endif // BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
119