Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:19:57

0001 /*******************************************************************************
0002  * Copyright (c) The JETSCAPE Collaboration, 2018
0003  *
0004  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
0005  * 
0006  * For the list of contributors see AUTHORS.
0007  *
0008  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
0009  *
0010  * or via email to bugs.jetscape@gmail.com
0011  *
0012  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
0013  * See COPYING for details.
0014  ******************************************************************************/
0015 
0016 /*******************************************************************************
0017  * Allow C++14 style make_unique for C++11
0018  * Taken from STL's solution,
0019  * https://isocpp.org/files/papers/N3656.txt
0020  ******************************************************************************/
0021 
0022 #ifndef MAKEUNIQUEHELPER_H
0023 #define MAKEUNIQUEHELPER_H
0024 
0025 #include <cstddef>
0026 #include <memory>
0027 #include <type_traits>
0028 #include <utility>
0029 
0030 namespace Jetscape {
0031 template <class T> struct _Unique_if {
0032   typedef std::unique_ptr<T> _Single_object;
0033 };
0034 
0035 template <class T> struct _Unique_if<T[]> {
0036   typedef std::unique_ptr<T[]> _Unknown_bound;
0037 };
0038 
0039 template <class T, size_t N> struct _Unique_if<T[N]> {
0040   typedef void _Known_bound;
0041 };
0042 
0043 template <class T, class... Args>
0044 typename _Unique_if<T>::_Single_object make_unique(Args &&... args) {
0045   return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
0046 }
0047 
0048 template <class T>
0049 typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) {
0050   typedef typename std::remove_extent<T>::type U;
0051   return std::unique_ptr<T>(new U[n]());
0052 }
0053 
0054 template <class T, class... Args>
0055 typename _Unique_if<T>::_Known_bound make_unique(Args &&...) = delete;
0056 
0057 // check whether a weak pointer is initialized or not
0058 template <typename T>
0059 bool weak_ptr_is_uninitialized(std::weak_ptr<T> const &weak) {
0060   using wt = std::weak_ptr<T>;
0061   return !weak.owner_before(wt{}) && !wt{}.owner_before(weak);
0062 }
0063 
0064 } // namespace Jetscape
0065 
0066 #endif // MAKEUNIQUEHELPER_H