blob: 1d0a92ac958a1547761e1dc5e5f60b0edb4c0249 [file] [log] [blame]
Davide Pesavento409cc202015-09-19 14:13:16 +02001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventocf415762017-02-25 23:46:47 -05003 * Copyright (c) 2015-2017 Regents of the University of California.
Davide Pesavento409cc202015-09-19 14:13:16 +02004 *
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 Pesavento96b96af2015-09-19 23:00:40 +020027#ifndef NDN_CXX_HAVE_STD_TO_STRING
28#include <boost/lexical_cast.hpp>
29#endif
30
Davide Pesavento409cc202015-09-19 14:13:16 +020031namespace ndn {
32
Davide Pesaventocf415762017-02-25 23:46:47 -050033#if __cpp_lib_make_unique >= 201304
Davide Pesavento409cc202015-09-19 14:13:16 +020034using std::make_unique;
35#else
Junxiao Shi1aecae22016-08-30 11:23:59 +000036template<typename T, typename ...Args>
Davide Pesavento409cc202015-09-19 14:13:16 +020037inline unique_ptr<T>
38make_unique(Args&&... args)
39{
40 return unique_ptr<T>(new T(std::forward<Args>(args)...));
41}
42#endif // __cpp_lib_make_unique
43
Davide Pesavento96b96af2015-09-19 23:00:40 +020044#ifdef NDN_CXX_HAVE_STD_TO_STRING
45using std::to_string;
46#else
47template<typename V>
48inline std::string
49to_string(const V& v)
50{
51 return boost::lexical_cast<std::string>(v);
52}
53#endif // NDN_CXX_HAVE_STD_TO_STRING
54
Weiwei Liucfaa1ad2016-08-28 16:30:56 -070055#if __cpp_lib_clamp >= 201603
56using std::clamp;
57#else
58template<typename T, typename Compare>
59constexpr const T&
60clamp(const T& v, const T& lo, const T& hi, Compare comp)
61{
62 return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
63}
64
65template<typename T>
66constexpr const T&
67clamp(const T& v, const T& lo, const T& hi)
68{
69 return (v < lo) ? lo : (hi < v) ? hi : v;
70}
71#endif // __cpp_lib_clamp
72
Davide Pesavento409cc202015-09-19 14:13:16 +020073} // namespace ndn
74
Junxiao Shi1aecae22016-08-30 11:23:59 +000075#include "backports-optional.hpp"
Davide Pesaventocf415762017-02-25 23:46:47 -050076#include "backports-ostream-joiner.hpp"
Junxiao Shi1aecae22016-08-30 11:23:59 +000077
Davide Pesavento409cc202015-09-19 14:13:16 +020078#endif // NDN_UTIL_BACKPORTS_HPP