PIDUINO
Loading...
Searching...
No Matches
memory.h
1/* Copyright © 2018-2025 Pascal JEAN, All rights reserved.
2 * This file is part of the Piduino Library.
3 *
4 * The Piduino Library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * The Piduino Library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with the Piduino Library; if not, see <http://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <memory>
20
21#ifndef __cpp_lib_make_unique
22// defined make_unique if < c++14
23#include <cstddef>
24#include <type_traits>
25#include <utility>
26
27namespace std {
28 template<class T> struct _Unique_if {
29 typedef unique_ptr<T> _Single_object;
30 };
31
32 template<class T> struct _Unique_if<T[]> {
33 typedef unique_ptr<T[]> _Unknown_bound;
34 };
35
36 template<class T, size_t N> struct _Unique_if<T[N]> {
37 typedef void _Known_bound;
38 };
39
40 template<class T, class... Args>
42 make_unique (Args && ... args) {
43 return unique_ptr<T> (new T (std::forward<Args> (args)...));
44 }
45
46 template<class T>
47 typename _Unique_if<T>::_Unknown_bound
48 make_unique (size_t n) {
49 typedef typename remove_extent<T>::type U;
50 return unique_ptr<T> (new U[n]());
51 }
52
53 template<class T, class... Args>
54 typename _Unique_if<T>::_Known_bound
55 make_unique (Args && ...) = delete;
56}
57#endif /* __cpp_lib_make_unique not defined */
58
59/* ========================================================================== */
STL namespace.
_Unique_if< T >::_Single_object make_unique(Args &&... args)
Definition memory.h:42
unique_ptr< T[]> _Unknown_bound
Definition memory.h:33
unique_ptr< T > _Single_object
Definition memory.h:29