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() 82 #include "ndn-cxx/util/nonstd/any.hpp" 83 #include "ndn-cxx/util/nonstd/optional.hpp" 84 #include "ndn-cxx/util/nonstd/variant.hpp" 86 #ifndef NDN_CXX_HAVE_STD_TO_STRING 87 #include <boost/lexical_cast.hpp> 96 #ifdef NDN_CXX_HAVE_STD_TO_STRING 103 return boost::lexical_cast<std::string>(val);
105 #endif // NDN_CXX_HAVE_STD_TO_STRING 111 #if __cpp_lib_clamp >= 201603L 114 template<
typename T,
typename Compare>
116 clamp(
const T& v,
const T& lo,
const T& hi, Compare comp)
118 BOOST_ASSERT(!comp(hi, lo));
119 return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
124 clamp(
const T& v,
const T& lo,
const T& hi)
126 BOOST_ASSERT(!(hi < lo));
127 return (v < lo) ? lo : (hi < v) ? hi : v;
129 #endif // __cpp_lib_clamp 135 #if __cpp_lib_to_underlying >= 202002L 139 constexpr std::underlying_type_t<T>
142 static_assert(std::is_enum<T>::value,
"");
143 return static_cast<std::underlying_type_t<T>
>(val);
145 #endif // __cpp_lib_to_underlying 148 using ::nonstd::any_cast;
149 using ::nonstd::bad_any_cast;
150 using ::nonstd::make_any;
152 using ::nonstd::optional;
153 using ::nonstd::bad_optional_access;
154 using ::nonstd::nullopt;
155 using ::nonstd::nullopt_t;
156 using ::nonstd::in_place;
157 using ::nonstd::in_place_t;
158 using ::nonstd::make_optional;
160 using ::nonstd::variant;
161 using ::nonstd::bad_variant_access;
162 using ::nonstd::monostate;
163 using ::nonstd::variant_npos;
165 using ::nonstd::get_if;
166 using ::nonstd::holds_alternative;
167 using ::nonstd::visit;
171 #endif // NDN_UTIL_BACKPORTS_HPP
std::string to_string(const T &val)
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Common includes and macros used throughout the library.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
constexpr std::underlying_type_t< T > to_underlying(T val) noexcept