]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/test/data/monomorphic/singleton.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / test / data / monomorphic / singleton.hpp
CommitLineData
7c673cae
FG
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
23namespace boost {
24namespace unit_test {
25namespace data {
26namespace monomorphic {
27
28// ************************************************************************** //
29// ************** singleton ************** //
30// ************************************************************************** //
31
32/// Models a single element data set
33template<typename T>
34class singleton {
92f5a8d4 35private:
7c673cae
FG
36 typedef typename boost::decay<T>::type sample;
37
92f5a8d4
TL
38public:
39
7c673cae
FG
40 enum { arity = 1 };
41
42 struct iterator {
43 // Constructor
44 explicit iterator( singleton<T> const* owner )
45 : m_owner( owner )
46 {}
47
48 // forward iterator interface
49 sample const& operator*() const { return m_owner->value(); }
50 void operator++() {}
51
52 private:
53 singleton<T> const* m_owner;
54 };
55
56 //! Constructor
57 explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {}
58
59 //! Move constructor
60 singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {}
61
62 //! Value access method
63 T const& value() const { return m_value; }
64
65 //! dataset interface
66 data::size_t size() const { return 1; }
67 iterator begin() const { return iterator( this ); }
68
69private:
70 // Data members
71 T m_value;
72};
73
74//____________________________________________________________________________//
75
76// a singleton is a dataset
77template<typename T>
78struct is_dataset<singleton<T>> : mpl::true_ {};
79
80//____________________________________________________________________________//
81
82} // namespace monomorphic
83
84/// @overload boost::unit_test::data::make()
85template<typename T>
b32b8144 86inline typename std::enable_if<!is_container_forward_iterable<T>::value &&
7c673cae
FG
87 !monomorphic::is_dataset<T>::value &&
88 !boost::is_array<typename boost::remove_reference<T>::type>::value,
89 monomorphic::singleton<T>
90>::type
91make( T&& v )
92{
93 return monomorphic::singleton<T>( std::forward<T>( v ) );
94}
95
96//____________________________________________________________________________//
97
98/// @overload boost::unit_test::data::make
99inline monomorphic::singleton<char*>
100make( char* str )
101{
102 return monomorphic::singleton<char*>( std::move(str) );
103}
104
105//____________________________________________________________________________//
106
107/// @overload boost::unit_test::data::make
108inline monomorphic::singleton<char const*>
109make( char const* str )
110{
111 return monomorphic::singleton<char const*>( std::move(str) );
112}
113
114} // namespace data
115} // namespace unit_test
116} // namespace boost
117
118#include <boost/test/detail/enable_warnings.hpp>
119
120#endif // BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
121