19 #ifndef GRPC_CORE_LIB_GPRPP_MANUAL_CONSTRUCTOR_H 20 #define GRPC_CORE_LIB_GPRPP_MANUAL_CONSTRUCTOR_H 29 #include <type_traits> 38 namespace manual_ctor_impl {
42 template <
class Member,
class... List>
45 template <
class Member,
class... List>
48 static constexpr
const bool value =
true;
51 template <
class Member,
class A,
class... List>
54 static constexpr
const bool value =
is_one_of<Member, List...>::value;
57 template <
class Member>
60 static constexpr
const bool value =
false;
65 template <
class... Types>
71 static constexpr
const size_t value =
sizeof(A);
74 template <
class A,
class... B>
84 template <
class... Types>
90 static constexpr
const size_t value =
alignof(A);
93 template <
class A,
class... B>
103 template <
class BaseType,
class... DerivedTypes>
111 BaseType*
get() {
return reinterpret_cast<BaseType*
>(&space_); }
112 const BaseType*
get()
const {
113 return reinterpret_cast<const BaseType*
>(&space_);
122 template <
class DerivedType>
124 FinishInit(
new (&space_) DerivedType);
133 template <
class DerivedType,
typename... Ts>
135 FinishInit(
new (&space_) DerivedType(std::forward<Ts>(args)...));
142 template <
class DerivedType>
143 void Init(
const DerivedType& x) {
144 FinishInit(
new (&space_) DerivedType(x));
146 template <
class DerivedType>
148 FinishInit(
new (&space_) DerivedType(std::move(x)));
154 template <
class DerivedType>
155 void FinishInit(DerivedType* p) {
158 "DerivedType must be one of the predeclared DerivedTypes");
162 typename std::aligned_storage<
168 template <
typename Type>
176 Type*
get() {
return reinterpret_cast<Type*
>(&space_); }
177 const Type*
get()
const {
return reinterpret_cast<const Type*
>(&space_); }
185 void Init() {
new (&space_) Type; }
193 template <
typename... Ts>
195 new (&space_) Type(std::forward<Ts>(args)...);
202 void Init(
const Type& x) {
new (&space_) Type(x); }
203 void Init(Type&& x) {
new (&space_) Type(std::move(x)); }
208 typename std::aligned_storage<sizeof(Type), alignof(Type)>::type space_;
BaseType & operator*()
Definition: manual_constructor.h:119
Definition: manual_constructor.h:43
Definition: manual_constructor.h:85
Type * operator->()
Definition: manual_constructor.h:179
void Init(Type &&x)
Definition: manual_constructor.h:203
const Type * operator->() const
Definition: manual_constructor.h:180
const Type & operator*() const
Definition: manual_constructor.h:183
Round Robin Policy.
Definition: backend_metric.cc:24
const BaseType & operator*() const
Definition: manual_constructor.h:120
void Init(const Type &x)
Definition: manual_constructor.h:202
void Destroy()
Definition: manual_constructor.h:151
void Destroy()
Definition: manual_constructor.h:205
Definition: manual_constructor.h:104
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:94
void Init(Ts &&... args)
Definition: manual_constructor.h:134
void Init()
Definition: manual_constructor.h:123
Definition: manual_constructor.h:66
Type & operator*()
Definition: manual_constructor.h:182
Definition: manual_constructor.h:169
BaseType * operator->()
Definition: manual_constructor.h:116
void Init(DerivedType &&x)
Definition: manual_constructor.h:147
const BaseType * operator->() const
Definition: manual_constructor.h:117
void Init(Ts &&... args)
Definition: manual_constructor.h:194
void Init()
Definition: manual_constructor.h:185
void Init(const DerivedType &x)
Definition: manual_constructor.h:143