libcopp  1.2.0
standard_new_allocator.h
Go to the documentation of this file.
1 
10 #ifndef COTASK_CORE_STANDARD_NEW_ALLOCATOR_H
11 #define COTASK_CORE_STANDARD_NEW_ALLOCATOR_H
12 
13 #pragma once
14 
15 #include <libcopp/utils/features.h>
17 
18 namespace cotask {
19  namespace core {
21  public:
22 #if defined(COPP_MACRO_ENABLE_VARIADIC_TEMPLATE) && COPP_MACRO_ENABLE_VARIADIC_TEMPLATE
23 
28  template <typename Ty, typename... TARGS>
29  static std::shared_ptr<Ty> allocate(Ty *, TARGS COPP_MACRO_RV_REF... args) {
30  return std::make_shared<Ty>(COPP_MACRO_STD_FORWARD(TARGS, args)...);
31  }
32 
33 #else
34 
38  template <typename Ty>
39  static std::shared_ptr<Ty> allocate(Ty *) {
40  return std::make_shared<Ty>();
41  }
42 
48  template <typename Ty, typename TARG0>
49  static std::shared_ptr<Ty> allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0) {
50  return std::make_shared<Ty>(COPP_MACRO_STD_FORWARD(TARG0, arg0));
51  }
52 
59  template <typename Ty, typename TARG0, typename TARG1>
60  static std::shared_ptr<Ty> allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1) {
61  return std::make_shared<Ty>(COPP_MACRO_STD_FORWARD(TARG0, arg0), COPP_MACRO_STD_FORWARD(TARG1, arg1));
62  }
63 
71  template <typename Ty, typename TARG0, typename TARG1, typename TARG2>
72  static std::shared_ptr<Ty> allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1,
73  TARG2 COPP_MACRO_RV_REF arg2) {
74  return std::make_shared<Ty>(COPP_MACRO_STD_FORWARD(TARG0, arg0), COPP_MACRO_STD_FORWARD(TARG1, arg1),
75  COPP_MACRO_STD_FORWARD(TARG2, arg2));
76  }
77 
86  template <typename Ty, typename TARG0, typename TARG1, typename TARG2, typename TARG3>
87  static std::shared_ptr<Ty> allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1,
88  TARG2 COPP_MACRO_RV_REF arg2, TARG3 COPP_MACRO_RV_REF arg3) {
89  return std::make_shared<Ty>(COPP_MACRO_STD_FORWARD(TARG0, arg0), COPP_MACRO_STD_FORWARD(TARG1, arg1),
90  COPP_MACRO_STD_FORWARD(TARG2, arg2), COPP_MACRO_STD_FORWARD(TARG3, arg3));
91  }
92 
102  template <typename Ty, typename TARG0, typename TARG1, typename TARG2, typename TARG3, typename TARG4>
103  static std::shared_ptr<Ty> allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1,
104  TARG2 COPP_MACRO_RV_REF arg2, TARG3 COPP_MACRO_RV_REF arg3, TARG4 COPP_MACRO_RV_REF arg4) {
105  return std::make_shared<Ty>(COPP_MACRO_STD_FORWARD(TARG0, arg0), COPP_MACRO_STD_FORWARD(TARG1, arg1),
106  COPP_MACRO_STD_FORWARD(TARG2, arg2), COPP_MACRO_STD_FORWARD(TARG3, arg3),
107  COPP_MACRO_STD_FORWARD(TARG4, arg4));
108  }
109 
110 #endif
111  template <typename Ty>
112  static void deallocate(std::shared_ptr<Ty> &) {}
113  };
114  }
115 }
116 
117 
118 #endif /* STANDARD_NEW_ALLOCATOR_H_ */
static std::shared_ptr< Ty > allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1, TARG2 COPP_MACRO_RV_REF arg2)
allocate a object with 3 parameter(s).
static void deallocate(std::shared_ptr< Ty > &)
static std::shared_ptr< Ty > allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1)
allocate a object with 2 parameter(s).
static std::shared_ptr< Ty > allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0)
allocate a object with 1 parameter(s).
#define COPP_MACRO_STD_FORWARD(t, x)
Definition: features.h:175
static std::shared_ptr< Ty > allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1, TARG2 COPP_MACRO_RV_REF arg2, TARG3 COPP_MACRO_RV_REF arg3)
allocate a object with 4 parameter(s).
#define COPP_MACRO_RV_REF
Definition: features.h:167
static std::shared_ptr< Ty > allocate(Ty *, TARG0 COPP_MACRO_RV_REF arg0, TARG1 COPP_MACRO_RV_REF arg1, TARG2 COPP_MACRO_RV_REF arg2, TARG3 COPP_MACRO_RV_REF arg3, TARG4 COPP_MACRO_RV_REF arg4)
allocate a object with 5 parameter(s).
导入智能指针库 Licensed under the MIT licenses.
static std::shared_ptr< Ty > allocate(Ty *)
allocate a object with 0 parameter(s).