Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Weiwei Liu | cfaa1ad | 2016-08-28 16:30:56 -0700 | [diff] [blame] | 3 | * Copyright (c) 2015-2016 Regents of the University of California. |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 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 | |
| 25 | #include "../common.hpp" |
| 26 | |
Davide Pesavento | 96b96af | 2015-09-19 23:00:40 +0200 | [diff] [blame] | 27 | #ifndef NDN_CXX_HAVE_STD_TO_STRING |
| 28 | #include <boost/lexical_cast.hpp> |
| 29 | #endif |
| 30 | |
Weiwei Liu | cfaa1ad | 2016-08-28 16:30:56 -0700 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 33 | namespace ndn { |
| 34 | |
| 35 | #if __cpp_lib_make_unique |
| 36 | using std::make_unique; |
| 37 | #else |
Junxiao Shi | 1aecae2 | 2016-08-30 11:23:59 +0000 | [diff] [blame] | 38 | template<typename T, typename ...Args> |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 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 | |
Davide Pesavento | 96b96af | 2015-09-19 23:00:40 +0200 | [diff] [blame] | 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 | |
Weiwei Liu | cfaa1ad | 2016-08-28 16:30:56 -0700 | [diff] [blame] | 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 | |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 75 | } // namespace ndn |
| 76 | |
Junxiao Shi | 1aecae2 | 2016-08-30 11:23:59 +0000 | [diff] [blame] | 77 | #include "backports-optional.hpp" |
| 78 | |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 79 | #endif // NDN_UTIL_BACKPORTS_HPP |