42 #ifndef NDN_UTIL_BACKPORTS_OPTIONAL_HPP 43 #define NDN_UTIL_BACKPORTS_OPTIONAL_HPP 47 #if (__cplusplus > 201402L) && NDN_CXX_HAS_INCLUDE(<optional>) 49 # define NDN_CXX_HAVE_STD_OPTIONAL 50 #elif (__cplusplus > 201103L) && NDN_CXX_HAS_INCLUDE(<experimental/optional>) 51 # include <experimental/optional> 52 # if __cpp_lib_experimental_optional >= 201411 53 # define NDN_CXX_HAVE_EXPERIMENTAL_OPTIONAL 57 #if defined(NDN_CXX_HAVE_STD_OPTIONAL) 63 using std::bad_optional_access;
67 #elif defined(NDN_CXX_HAVE_EXPERIMENTAL_OPTIONAL) 70 using std::experimental::optional;
73 using std::experimental::bad_optional_access;
76 template<
typename T,
typename... Args>
80 return optional<T>(
in_place, std::forward<Args>(args)...);
86 #include <boost/none.hpp> 87 #include <boost/optional.hpp> 88 #include <boost/utility/typed_in_place_factory.hpp> 110 #if BOOST_VERSION >= 105600 111 using boost::bad_optional_access;
117 :
std::logic_error(
"bad optional access")
125 operator==(
const optional<T>& lhs,
const optional<T>& rhs);
129 operator!=(
const optional<T>& lhs,
const optional<T>& rhs);
133 operator<(const optional<T>& lhs,
const optional<T>& rhs);
137 operator<=(const optional<T>& lhs,
const optional<T>& rhs);
141 operator>(
const optional<T>& lhs,
const optional<T>& rhs);
145 operator>=(
const optional<T>& lhs,
const optional<T>& rhs);
151 static_assert(!std::is_same<
typename std::remove_cv<T>::type, in_place_t>::
value &&
152 !std::is_same<
typename std::remove_cv<T>::type, nullopt_t>::
value &&
153 !std::is_reference<T>::value,
154 "Invalid instantiation of optional<T>");
170 : m_boostOptional(
value)
174 template<
typename... Args>
184 m_boostOptional = boost::none;
191 m_boostOptional = other.m_boostOptional;
196 typename =
typename std::enable_if<std::is_same<typename std::decay<U>::type, T>
::value>::type>
200 m_boostOptional = std::forward<U>(
value);
208 return m_boostOptional.get_ptr();
214 return m_boostOptional.get_ptr();
220 return m_boostOptional.get();
226 return m_boostOptional.get();
230 operator bool() const noexcept
232 return static_cast<bool>(m_boostOptional);
244 #if BOOST_VERSION >= 105600 245 return m_boostOptional.value();
247 if (!m_boostOptional) {
250 return m_boostOptional.get();
258 #if BOOST_VERSION >= 105600 259 return m_boostOptional.value_or(default_value);
261 return m_boostOptional.get_value_or(default_value);
269 boost::swap(m_boostOptional, other.m_boostOptional);
275 m_boostOptional = boost::none;
278 template<
typename... Args>
282 m_boostOptional = boost::in_place<T>(std::forward<Args>(args)...);
286 boost::optional<T> m_boostOptional;
300 return operator==(lhs.m_boostOptional, rhs.m_boostOptional);
307 return operator!=(lhs.m_boostOptional, rhs.m_boostOptional);
314 return operator<(lhs.m_boostOptional, rhs.m_boostOptional);
321 return operator<=(lhs.m_boostOptional, rhs.m_boostOptional);
328 return operator>(lhs.m_boostOptional, rhs.m_boostOptional);
335 return operator>=(lhs.m_boostOptional, rhs.m_boostOptional);
339 constexpr optional<typename std::decay<T>::type>
345 template<
typename T,
typename... Args>
346 constexpr optional<T>
355 #endif // NDN_UTIL_BACKPORTS_OPTIONAL_HPP constexpr in_place_t in_place
constexpr nullopt_t nullopt
Copyright (c) 2011-2015 Regents of the University of California.
void swap(optional &other)
optional & operator=(const optional &other)
void emplace(Args &&... args)
constexpr T value_or(U &&default_value) const
constexpr optional(const T &value)
bool operator<=(const Delegation &lhs, const Delegation &rhs)
optional & operator=(nullopt_t) noexcept
bool operator!=(const Data &lhs, const Data &rhs)
constexpr optional(in_place_t, Args &&... args)
constexpr const T & operator*() const
constexpr optional() noexcept
constexpr optional< typename std::decay< T >::type > make_optional(T &&value)
bool operator>(const Delegation &lhs, const Delegation &rhs)
constexpr optional< T > make_optional(Args &&... args)
bool operator>=(const Delegation &lhs, const Delegation &rhs)
bool operator==(const Data &lhs, const Data &rhs)
optional & operator=(U &&value)
bool operator<(const Delegation &lhs, const Delegation &rhs)
constexpr const T * operator->() const
constexpr optional(nullopt_t) noexcept