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) 52 #define NDN_CXX_DEPRECATED NDN_CXX_DEPRECATED_MSG("") 54 #if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(fallthrough) 55 # define NDN_CXX_FALLTHROUGH [[fallthrough]] 56 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(clang::fallthrough) 57 # define NDN_CXX_FALLTHROUGH [[clang::fallthrough]] 58 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::fallthrough) 59 # define NDN_CXX_FALLTHROUGH [[gnu::fallthrough]] 60 #elif defined(__GNUC__) && (__GNUC__ >= 7) 61 # define NDN_CXX_FALLTHROUGH __attribute__((fallthrough)) 63 # define NDN_CXX_FALLTHROUGH ((void)0) 68 #if __cpp_lib_make_unique >= 201304 71 template<
typename T,
typename ...Args>
75 return unique_ptr<T>(
new T(std::forward<Args>(args)...));
77 #endif // __cpp_lib_make_unique 79 #ifdef NDN_CXX_HAVE_STD_TO_STRING 86 return boost::lexical_cast<std::string>(v);
88 #endif // NDN_CXX_HAVE_STD_TO_STRING 90 #if __cpp_lib_clamp >= 201603 93 template<
typename T,
typename Compare>
95 clamp(
const T& v,
const T& lo,
const T& hi, Compare comp)
97 return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
102 clamp(
const T& v,
const T& lo,
const T& hi)
104 return (v < lo) ? lo : (hi < v) ? hi : v;
106 #endif // __cpp_lib_clamp 113 #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)