22 #ifndef NDN_UTIL_BACKPORTS_HPP 23 #define NDN_UTIL_BACKPORTS_HPP 27 #include <boost/predef/compiler/clang.h> 28 #include <boost/predef/compiler/gcc.h> 29 #include <boost/predef/compiler/visualc.h> 31 #ifdef __has_cpp_attribute 32 # define NDN_CXX_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) 34 # define NDN_CXX_HAS_CPP_ATTRIBUTE(x) 0 38 # define NDN_CXX_HAS_INCLUDE(x) __has_include(x) 40 # define NDN_CXX_HAS_INCLUDE(x) 0 47 #if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(fallthrough) 48 # define NDN_CXX_FALLTHROUGH [[fallthrough]] 49 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(clang::fallthrough) 50 # define NDN_CXX_FALLTHROUGH [[clang::fallthrough]] 51 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::fallthrough) 52 # define NDN_CXX_FALLTHROUGH [[gnu::fallthrough]] 53 #elif BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(7,0,0) 54 # define NDN_CXX_FALLTHROUGH __attribute__((fallthrough)) 56 # define NDN_CXX_FALLTHROUGH ((void)0) 63 #if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(nodiscard) 64 # define NDN_CXX_NODISCARD [[nodiscard]] 65 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::warn_unused_result) 66 # define NDN_CXX_NODISCARD [[gnu::warn_unused_result]] 68 # define NDN_CXX_NODISCARD 72 # define NDN_CXX_UNREACHABLE BOOST_ASSERT(false) 73 #elif BOOST_COMP_GNUC || BOOST_COMP_CLANG 74 # define NDN_CXX_UNREACHABLE __builtin_unreachable() 76 # define NDN_CXX_UNREACHABLE __assume(0) 79 # define NDN_CXX_UNREACHABLE std::abort() 87 #ifndef NDN_CXX_HAVE_STD_TO_STRING 88 #include <boost/lexical_cast.hpp> 97 #ifdef NDN_CXX_HAVE_STD_TO_STRING 104 return boost::lexical_cast<std::string>(val);
106 #endif // NDN_CXX_HAVE_STD_TO_STRING 112 #if __cpp_lib_clamp >= 201603L 115 template<
typename T,
typename Compare>
117 clamp(
const T& v,
const T& lo,
const T& hi, Compare comp)
119 BOOST_ASSERT(!comp(hi, lo));
120 return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
125 clamp(
const T& v,
const T& lo,
const T& hi)
127 BOOST_ASSERT(!(hi < lo));
128 return (v < lo) ? lo : (hi < v) ? hi : v;
130 #endif // __cpp_lib_clamp 136 #if __cpp_lib_to_underlying >= 202002L 140 constexpr std::underlying_type_t<T>
143 static_assert(std::is_enum<T>::value,
"");
144 return static_cast<std::underlying_type_t<T>
>(val);
146 #endif // __cpp_lib_to_underlying 150 using ::nonstd::bad_any_cast;
151 using ::nonstd::make_any;
153 using ::nonstd::optional;
154 using ::nonstd::bad_optional_access;
156 using ::nonstd::nullopt_t;
158 using ::nonstd::in_place_t;
161 using ::nonstd::variant;
162 using ::nonstd::bad_variant_access;
163 using ::nonstd::monostate;
172 #endif // NDN_UTIL_BACKPORTS_HPP ValueType any_cast(any const &operand)
std::string to_string(const T &val)
optional< T > make_optional(T const &value)
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
static const std::size_t variant_npos
std11::add_pointer< T >::type get_if(variant< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > *pv, nonstd::in_place_t(&)(nonstd::detail::in_place_type_tag< T >)=nonstd::in_place_type< T >)
R & get(variant< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > &v, nonstd::in_place_t(&)(nonstd::detail::in_place_type_tag< R >)=nonstd::in_place_type< R >)
Backport of ostream_joiner from the Library Fundamentals v2 TS.
Common includes and macros used throughout the library.
bool holds_alternative(variant< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > const &v)
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
const nullopt_t nullopt((nullopt_t::init()))
in_place_t in_place(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
R visit(const Visitor &v, V1 const &arg1)