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")
133 operator<(const optional<T>& lhs,
const optional<T>& rhs);
137 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 &&
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);
272 template<
typename... Args>
276 m_boostOptional = boost::in_place<T>(std::forward<Args>(args)...);
280 boost::optional<T> m_boostOptional;
282 friend bool operator==<T>(
const optional<T>&,
const optional<T>&);
283 friend bool operator!=<T>(
const optional<T>&,
const optional<T>&);
284 friend bool operator< <T>(
const optional<T>&,
const optional<T>&);
285 friend bool operator<=<T>(
const optional<T>&,
const optional<T>&);
286 friend bool operator> <T>(
const optional<T>&,
const optional<T>&);
287 friend bool operator>=<T>(
const optional<T>&,
const optional<T>&);
294 return operator==(lhs.m_boostOptional, rhs.m_boostOptional);
301 return operator!=(lhs.m_boostOptional, rhs.m_boostOptional);
308 return operator<(lhs.m_boostOptional, rhs.m_boostOptional);
315 return operator<=(lhs.m_boostOptional, rhs.m_boostOptional);
322 return operator>(lhs.m_boostOptional, rhs.m_boostOptional);
329 return operator>=(lhs.m_boostOptional, rhs.m_boostOptional);
339 template<
typename T,
typename... Args>
349 #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)
Copyright (c) 2013-2017 Regents of the University of California.
optional & operator=(const optional &other)
constexpr optional< T > make_optional(Args &&...args)
constexpr const T & operator*() 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)
void emplace(Args &&...args)
constexpr optional() noexcept
constexpr T value_or(U &&default_value) const
constexpr optional< typename std::decay< T >::type > make_optional(T &&value)
bool operator>(const Delegation &lhs, const Delegation &rhs)
bool operator>=(const Delegation &lhs, const Delegation &rhs)
bool operator==(const Data &lhs, const Data &rhs)
optional & operator=(U &&value)
constexpr optional(in_place_t, Args &&...args)
bool operator<(const Delegation &lhs, const Delegation &rhs)
constexpr const T * operator->() const
constexpr optional(nullopt_t) noexcept