Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeUniqueHelper.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MakeUniqueHelper.h
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 
16 /*******************************************************************************
17  * Allow C++14 style make_unique for C++11
18  * Taken from STL's solution,
19  * https://isocpp.org/files/papers/N3656.txt
20  ******************************************************************************/
21 
22 #ifndef MAKEUNIQUEHELPER_H
23 #define MAKEUNIQUEHELPER_H
24 
25 #include <cstddef>
26 #include <memory>
27 #include <type_traits>
28 #include <utility>
29 
30 namespace Jetscape {
31 template <class T> struct _Unique_if {
32  typedef std::unique_ptr<T> _Single_object;
33 };
34 
35 template <class T> struct _Unique_if<T[]> {
36  typedef std::unique_ptr<T[]> _Unknown_bound;
37 };
38 
39 template <class T, size_t N> struct _Unique_if<T[N]> {
40  typedef void _Known_bound;
41 };
42 
43 template <class T, class... Args>
45  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
46 }
47 
48 template <class T>
50  typedef typename std::remove_extent<T>::type U;
51  return std::unique_ptr<T>(new U[n]());
52 }
53 
54 template <class T, class... Args>
55 typename _Unique_if<T>::_Known_bound make_unique(Args &&...) = delete;
56 
57 // check whether a weak pointer is initialized or not
58 template <typename T>
59 bool weak_ptr_is_uninitialized(std::weak_ptr<T> const &weak) {
60  using wt = std::weak_ptr<T>;
61  return !weak.owner_before(wt{}) && !wt{}.owner_before(weak);
62 }
63 
64 } // namespace Jetscape
65 
66 #endif // MAKEUNIQUEHELPER_H