NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_UTIL_BACKPORTS_HPP
23 #define NDN_UTIL_BACKPORTS_HPP
24 
26 
27 #ifdef __has_cpp_attribute
28 # define NDN_CXX_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
29 #else
30 # define NDN_CXX_HAS_CPP_ATTRIBUTE(x) 0
31 #endif
32 
33 #ifdef __has_include
34 # define NDN_CXX_HAS_INCLUDE(x) __has_include(x)
35 #else
36 # define NDN_CXX_HAS_INCLUDE(x) 0
37 #endif
38 
39 #if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(fallthrough)
40 # define NDN_CXX_FALLTHROUGH [[fallthrough]]
41 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(clang::fallthrough)
42 # define NDN_CXX_FALLTHROUGH [[clang::fallthrough]]
43 #elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
44 # define NDN_CXX_FALLTHROUGH [[gnu::fallthrough]]
45 #elif defined(__GNUC__) && (__GNUC__ >= 7)
46 # define NDN_CXX_FALLTHROUGH __attribute__((fallthrough))
47 #else
48 # define NDN_CXX_FALLTHROUGH ((void)0)
49 #endif
50 
55 
56 #ifndef NDN_CXX_HAVE_STD_TO_STRING
57 #include <boost/lexical_cast.hpp>
58 #endif
59 
60 namespace ndn {
61 
62 #ifdef NDN_CXX_HAVE_STD_TO_STRING
63 using std::to_string;
64 #else
65 template<typename V>
66 inline std::string
67 to_string(const V& v)
68 {
69  return boost::lexical_cast<std::string>(v);
70 }
71 #endif // NDN_CXX_HAVE_STD_TO_STRING
72 
73 #if __cpp_lib_clamp >= 201603
74 using std::clamp;
75 #else
76 template<typename T, typename Compare>
77 constexpr const T&
78 clamp(const T& v, const T& lo, const T& hi, Compare comp)
79 {
80  return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
81 }
82 
83 template<typename T>
84 constexpr const T&
85 clamp(const T& v, const T& lo, const T& hi)
86 {
87  return (v < lo) ? lo : (hi < v) ? hi : v;
88 }
89 #endif // __cpp_lib_clamp
90 
91 using ::nonstd::any;
93 using ::nonstd::bad_any_cast;
94 using ::nonstd::make_any;
95 
96 using ::nonstd::optional;
97 using ::nonstd::bad_optional_access;
99 using ::nonstd::nullopt_t;
101 using ::nonstd::in_place_t;
103 
104 using ::nonstd::variant;
105 using ::nonstd::bad_variant_access;
106 using ::nonstd::monostate;
111 
112 } // namespace ndn
113 
114 #endif // NDN_UTIL_BACKPORTS_HPP
Copyright (c) 2011-2015 Regents of the University of California.
optional< T > make_optional(T const &value)
Definition: optional.hpp:1496
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition: backports.hpp:78
any_nodiscard ValueType any_cast(any const &operand)
Definition: any.hpp:571
static const std::size_t variant_npos
Definition: variant.hpp:1012
Backport of ostream_joiner from the Library Fundamentals v2 TS.
import common constructs for ndn-cxx library internal use
detail::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_lite_in_place_type_t(T)=nonstd_lite_in_place_type(T))
Definition: variant.hpp:1629
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition: backports.hpp:85
bool holds_alternative(variant< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > const &v) variant_noexcept
Definition: variant.hpp:1546
std::string to_string(const V &v)
Definition: backports.hpp:67
const nullopt_t nullopt((nullopt_t::init()))
in_place_t in_place(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
Definition: any.hpp:114
R visit(const Visitor &v, V1 const &arg1)
Definition: variant.hpp:1953