22 #ifndef NDN_UTIL_BACKPORTS_HPP 23 #define NDN_UTIL_BACKPORTS_HPP 25 #include "../common.hpp" 27 #ifndef NDN_CXX_HAVE_STD_TO_STRING 28 #include <boost/lexical_cast.hpp> 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 43 #if (__cplusplus >= 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(deprecated) 44 # define NDN_CXX_DEPRECATED_MSG(msg) [[deprecated(msg)]] 45 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::deprecated) 46 # define NDN_CXX_DEPRECATED_MSG(msg) [[gnu::deprecated(msg)]] 47 #elif defined(__GNUC__) 48 # define NDN_CXX_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) 50 # define NDN_CXX_DEPRECATED_MSG(msg) 75 #define NDN_CXX_DEPRECATED NDN_CXX_DEPRECATED_MSG("") 77 #if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(fallthrough) 78 # define NDN_CXX_FALLTHROUGH [[fallthrough]] 79 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(clang::fallthrough) 80 # define NDN_CXX_FALLTHROUGH [[clang::fallthrough]] 81 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::fallthrough) 82 # define NDN_CXX_FALLTHROUGH [[gnu::fallthrough]] 83 #elif defined(__GNUC__) && (__GNUC__ >= 7) 84 # define NDN_CXX_FALLTHROUGH __attribute__((fallthrough)) 86 # define NDN_CXX_FALLTHROUGH ((void)0) 91 #if __cpp_lib_make_unique >= 201304 94 template<
typename T,
typename ...Args>
98 return unique_ptr<T>(
new T(std::forward<Args>(args)...));
100 #endif // __cpp_lib_make_unique 102 #ifdef NDN_CXX_HAVE_STD_TO_STRING 109 return boost::lexical_cast<std::string>(v);
111 #endif // NDN_CXX_HAVE_STD_TO_STRING 113 #if __cpp_lib_clamp >= 201603 116 template<
typename T,
typename Compare>
118 clamp(
const T& v,
const T& lo,
const T& hi, Compare comp)
120 return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
125 clamp(
const T& v,
const T& lo,
const T& hi)
127 return (v < lo) ? lo : (hi < v) ? hi : v;
129 #endif // __cpp_lib_clamp 136 #endif // NDN_UTIL_BACKPORTS_HPP Copyright (c) 2013-2017 Regents of the University of California.
unique_ptr< T > make_unique(Args &&...args)
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Backport of ostream_joiner from the Library Fundamentals v2 TS.
C++17 std::optional backport implemented using boost::optional.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
std::string to_string(const V &v)