File indexing completed on 2025-08-03 08:19:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
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
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 }
0065
0066 #endif