GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
gnss_sdr_make_unique.h
Go to the documentation of this file.
1/*!
2 * \file gnss_sdr_make_unique.h
3 * \brief This file implements std::make_unique for C++11
4 *
5 * \author Carles Fernandez-Prades, 2020. cfernandez(at)cttc.es
6 *
7 * Based on https://stackoverflow.com/a/17902439
8 *
9 *
10 * -----------------------------------------------------------------------------
11 *
12 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
13 * This file is part of GNSS-SDR.
14 *
15 * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
16 * SPDX-License-Identifier: GPL-3.0-or-later
17 *
18 * -----------------------------------------------------------------------------
19 */
20
21#ifndef GNSS_SDR_GNSS_SDR_MAKE_UNIQUE_H
22#define GNSS_SDR_GNSS_SDR_MAKE_UNIQUE_H
23
24#if __cplusplus == 201103L
25
26#include <cstddef>
27#include <memory>
28#include <type_traits>
29#include <utility>
30
31/** \addtogroup Algorithms_Library
32 * \{ */
33/** \addtogroup Algorithm_libs algorithms_libs
34 * \{ */
35
36
37namespace std
38{
39template <class T>
40struct _Unique_if
41{
42 typedef unique_ptr<T> _Single_object;
43};
44
45template <class T>
46struct _Unique_if<T[]>
47{
48 typedef unique_ptr<T[]> _Unknown_bound;
49};
50
51template <class T, size_t N>
52struct _Unique_if<T[N]>
53{
54 typedef void _Known_bound;
55};
56
57template <class T, class... Args>
58typename _Unique_if<T>::_Single_object
59make_unique(Args&&... args)
60{
61 return unique_ptr<T>(new T(std::forward<Args>(args)...));
62}
63
64template <class T>
65typename _Unique_if<T>::_Unknown_bound
66make_unique(size_t n)
67{
68 typedef typename remove_extent<T>::type U;
69 return unique_ptr<T>(new U[n]());
70}
71
72template <class T, class... Args>
73typename _Unique_if<T>::_Known_bound
74make_unique(Args&&...) = delete;
75} // namespace std
76
77#endif // __cplusplus == 201103L
78
79
80/** \} */
81/** \} */
82#endif // GNSS_SDR_GNSS_SDR_MAKE_UNIQUE_H
STL namespace.