1/*
2Copyright 2018 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7*/
8#ifndef BOOST_CORE_EMPTY_VALUE_HPP
9#define BOOST_CORE_EMPTY_VALUE_HPP
10
11#include <boost/config.hpp>
12#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
13#include <utility>
14#endif
15
16#if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 40700)
17#define BOOST_DETAIL_EMPTY_VALUE_BASE
18#elif defined(BOOST_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1800)
19#define BOOST_DETAIL_EMPTY_VALUE_BASE
20#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1800)
21#define BOOST_DETAIL_EMPTY_VALUE_BASE
22#elif defined(BOOST_CLANG) && !defined(__CUDACC__)
23#if __has_feature(is_empty) && __has_feature(is_final)
24#define BOOST_DETAIL_EMPTY_VALUE_BASE
25#endif
26#endif
27
28#if defined(_MSC_VER)
29#pragma warning(push)
30#pragma warning(disable:4510)
31#endif
32
33namespace boost {
34
35template<class T>
36struct use_empty_value_base {
37 enum {
38#if defined(BOOST_DETAIL_EMPTY_VALUE_BASE)
39 value = __is_empty(T) && !__is_final(T)
40#else
41 value = false
42#endif
43 };
44};
45
46struct empty_init_t { };
47
48namespace empty_ {
49
50template<class T, unsigned N = 0,
51 bool E = boost::use_empty_value_base<T>::value>
52class empty_value {
53public:
54 typedef T type;
55
56#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
57 empty_value() = default;
58#else
59 BOOST_CONSTEXPR empty_value() { }
60#endif
61
62 BOOST_CONSTEXPR empty_value(boost::empty_init_t)
63 : value_() { }
64
65#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
66#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
67 template<class U, class... Args>
68 BOOST_CONSTEXPR empty_value(boost::empty_init_t, U&& value, Args&&... args)
69 : value_(std::forward<U>(value), std::forward<Args>(args)...) { }
70#else
71 template<class U>
72 BOOST_CONSTEXPR empty_value(boost::empty_init_t, U&& value)
73 : value_(std::forward<U>(value)) { }
74#endif
75#else
76 template<class U>
77 BOOST_CONSTEXPR empty_value(boost::empty_init_t, const U& value)
78 : value_(value) { }
79
80 template<class U>
81 BOOST_CONSTEXPR empty_value(boost::empty_init_t, U& value)
82 : value_(value) { }
83#endif
84
85 BOOST_CONSTEXPR const T& get() const BOOST_NOEXCEPT {
86 return value_;
87 }
88
89 BOOST_CXX14_CONSTEXPR T& get() BOOST_NOEXCEPT {
90 return value_;
91 }
92
93private:
94 T value_;
95};
96
97#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
98template<class T, unsigned N>
99class empty_value<T, N, true>
100 : T {
101public:
102 typedef T type;
103
104#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
105 empty_value() = default;
106#else
107 BOOST_CONSTEXPR empty_value() { }
108#endif
109
110 BOOST_CONSTEXPR empty_value(boost::empty_init_t)
111 : T() { }
112
113#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
114#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
115 template<class U, class... Args>
116 BOOST_CONSTEXPR empty_value(boost::empty_init_t, U&& value, Args&&... args)
117 : T(std::forward<U>(value), std::forward<Args>(args)...) { }
118#else
119 template<class U>
120 BOOST_CONSTEXPR empty_value(boost::empty_init_t, U&& value)
121 : T(std::forward<U>(value)) { }
122#endif
123#else
124 template<class U>
125 BOOST_CONSTEXPR empty_value(boost::empty_init_t, const U& value)
126 : T(value) { }
127
128 template<class U>
129 BOOST_CONSTEXPR empty_value(boost::empty_init_t, U& value)
130 : T(value) { }
131#endif
132
133 BOOST_CONSTEXPR const T& get() const BOOST_NOEXCEPT {
134 return *this;
135 }
136
137 BOOST_CXX14_CONSTEXPR T& get() BOOST_NOEXCEPT {
138 return *this;
139 }
140};
141#endif
142
143} /* empty_ */
144
145using empty_::empty_value;
146
147BOOST_INLINE_CONSTEXPR empty_init_t empty_init = empty_init_t();
148
149} /* boost */
150
151#if defined(_MSC_VER)
152#pragma warning(pop)
153#endif
154
155#endif
156