NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
backports.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_BACKPORTS_HPP
23 #define NDN_UTIL_BACKPORTS_HPP
24 
25 #include "../common.hpp"
26 
27 #ifndef NDN_CXX_HAVE_STD_TO_STRING
28 #include <boost/lexical_cast.hpp>
29 #endif
30 
31 #include <algorithm>
32 
33 namespace ndn {
34 
35 #if __cpp_lib_make_unique
36 using std::make_unique;
37 #else
38 template<typename T, typename ...Args>
39 inline unique_ptr<T>
40 make_unique(Args&&... args)
41 {
42  return unique_ptr<T>(new T(std::forward<Args>(args)...));
43 }
44 #endif // __cpp_lib_make_unique
45 
46 #ifdef NDN_CXX_HAVE_STD_TO_STRING
47 using std::to_string;
48 #else
49 template<typename V>
50 inline std::string
51 to_string(const V& v)
52 {
53  return boost::lexical_cast<std::string>(v);
54 }
55 #endif // NDN_CXX_HAVE_STD_TO_STRING
56 
57 #if __cpp_lib_clamp >= 201603
58 using std::clamp;
59 #else
60 template<typename T, typename Compare>
61 constexpr const T&
62 clamp(const T& v, const T& lo, const T& hi, Compare comp)
63 {
64  return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
65 }
66 
67 template<typename T>
68 constexpr const T&
69 clamp(const T& v, const T& lo, const T& hi)
70 {
71  return (v < lo) ? lo : (hi < v) ? hi : v;
72 }
73 #endif // __cpp_lib_clamp
74 
75 } // namespace ndn
76 
77 #include "backports-optional.hpp"
78 
79 #endif // NDN_UTIL_BACKPORTS_HPP
Copyright (c) 2011-2015 Regents of the University of California.
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition: backports.hpp:62
Copyright (c) 2013-2016 Regents of the University of California.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition: backports.hpp:69
std::string to_string(const V &v)
Definition: backports.hpp:51
unique_ptr< T > make_unique(Args &&... args)
Definition: backports.hpp:40