42 #ifndef NDN_UTIL_BACKPORTS_OPTIONAL_HPP 43 #define NDN_UTIL_BACKPORTS_OPTIONAL_HPP 45 #include "../common.hpp" 47 #include <boost/none.hpp> 48 #include <boost/optional.hpp> 49 #include <boost/utility/typed_in_place_factory.hpp> 71 #if BOOST_VERSION >= 105600 72 using boost::bad_optional_access;
78 :
std::logic_error(
"bad optional access")
94 operator<(const optional<T>& lhs,
const optional<T>& rhs);
98 operator<=(const optional<T>& lhs,
const optional<T>& rhs);
112 static_assert(!std::is_same<
typename std::remove_cv<T>::type,
in_place_t>::value &&
113 !std::is_same<
typename std::remove_cv<T>::type,
nullopt_t>::value &&
114 !std::is_reference<T>::value,
115 "Invalid instantiation of optional<T>");
131 : m_boostOptional(value)
135 template<
typename... Args>
145 m_boostOptional = boost::none;
152 m_boostOptional = other.m_boostOptional;
157 typename =
typename std::enable_if<std::is_same<typename std::decay<U>::type, T>::value>::type>
161 m_boostOptional = std::forward<U>(value);
169 return m_boostOptional.get_ptr();
175 return m_boostOptional.get_ptr();
181 return m_boostOptional.get();
187 return m_boostOptional.get();
191 operator bool() const noexcept
193 return static_cast<bool>(m_boostOptional);
199 return const_cast<optional*
>(
this)->value();
205 #if BOOST_VERSION >= 105600 206 return m_boostOptional.value();
208 if (!m_boostOptional) {
211 return m_boostOptional.get();
219 #if BOOST_VERSION >= 105600 220 return m_boostOptional.value_or(default_value);
222 return m_boostOptional.get_value_or(default_value);
230 boost::swap(m_boostOptional, other.m_boostOptional);
233 template<
typename... Args>
237 m_boostOptional = boost::in_place<T>(std::forward<Args>(args)...);
241 boost::optional<T> m_boostOptional;
243 friend bool operator==<T>(
const optional<T>&,
const optional<T>&);
244 friend bool operator!=<T>(
const optional<T>&,
const optional<T>&);
245 friend bool operator< <T>(
const optional<T>&,
const optional<T>&);
246 friend bool operator<=<T>(
const optional<T>&,
const optional<T>&);
247 friend bool operator> <T>(
const optional<T>&,
const optional<T>&);
248 friend bool operator>=<T>(
const optional<T>&,
const optional<T>&);
255 return operator==(lhs.m_boostOptional, rhs.m_boostOptional);
262 return operator!=(lhs.m_boostOptional, rhs.m_boostOptional);
269 return operator<(lhs.m_boostOptional, rhs.m_boostOptional);
276 return operator<=(lhs.m_boostOptional, rhs.m_boostOptional);
283 return operator>(lhs.m_boostOptional, rhs.m_boostOptional);
290 return operator>=(lhs.m_boostOptional, rhs.m_boostOptional);
300 template<
typename T,
typename... Args>
309 #endif // NDN_UTIL_BACKPORTS_OPTIONAL_HPP constexpr in_place_t in_place
Copyright (c) 2011-2015 Regents of the University of California.
void swap(optional &other)
Copyright (c) 2013-2016 Regents of the University of California.
optional & operator=(const optional &other)
void emplace(Args &&... args)
constexpr T value_or(U &&default_value) const
constexpr nullopt_t nullopt(0)
constexpr optional(const T &value)
optional & operator=(nullopt_t) noexcept
constexpr optional(in_place_t, Args &&... args)
bool operator>(const Exclude::ExcludeComponent &a, const Exclude::ExcludeComponent &b)
constexpr const T & operator*() const
constexpr optional() noexcept
bool operator==(const Exclude::ExcludeComponent &a, const Exclude::ExcludeComponent &b)
constexpr bool operator<(const optional< T > &lhs, const optional< T > &rhs)
constexpr optional< typename std::decay< T >::type > make_optional(T &&value)
constexpr bool operator<=(const optional< T > &lhs, const optional< T > &rhs)
constexpr bool operator!=(const optional< T > &lhs, const optional< T > &rhs)
optional & operator=(U &&value)
constexpr bool operator>=(const optional< T > &lhs, const optional< T > &rhs)
constexpr const T * operator->() const
constexpr optional(nullopt_t) noexcept