WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
make_unique.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 // Define make_unique for C++11-only compilers
11 #if __cplusplus == 201103L
12 #include <cstddef>
13 #include <memory>
14 #include <type_traits>
15 #include <utility>
16 
17 namespace std {
18 template <class T>
19 struct _Unique_if {
20  typedef unique_ptr<T> _Single_object;
21 };
22 
23 template <class T>
24 struct _Unique_if<T[]> {
25  typedef unique_ptr<T[]> _Unknown_bound;
26 };
27 
28 template <class T, size_t N>
29 struct _Unique_if<T[N]> {
30  typedef void _Known_bound;
31 };
32 
33 template <class T, class... Args>
34 typename _Unique_if<T>::_Single_object make_unique(Args&&... args) {
35  return unique_ptr<T>(new T(std::forward<Args>(args)...));
36 }
37 
38 template <class T>
39 typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) {
40  typedef typename remove_extent<T>::type U;
41  return unique_ptr<T>(new U[n]());
42 }
43 
44 template <class T, class... Args>
45 typename _Unique_if<T>::_Known_bound make_unique(Args&&...) = delete;
46 } // namespace std
47 #endif