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::forward<DerivedType>(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_;
Definition: manual_constructor.h:169
const Type * operator->() const
Definition: manual_constructor.h:180
Type & operator*()
Definition: manual_constructor.h:182
const Type & operator*() const
Definition: manual_constructor.h:183
void Destroy()
Definition: manual_constructor.h:205
Type * operator->()
Definition: manual_constructor.h:179
Type * get()
Definition: manual_constructor.h:176
void Init(Ts &&... args)
Definition: manual_constructor.h:194
const Type * get() const
Definition: manual_constructor.h:177
void Init(const Type &x)
Definition: manual_constructor.h:202
void Init()
Definition: manual_constructor.h:185
void Init(Type &&x)
Definition: manual_constructor.h:203
Definition: manual_constructor.h:104
void Init(const DerivedType &x)
Definition: manual_constructor.h:143
BaseType * operator->()
Definition: manual_constructor.h:116
void Destroy()
Definition: manual_constructor.h:151
void Init(Ts &&... args)
Definition: manual_constructor.h:134
BaseType & operator*()
Definition: manual_constructor.h:119
void Init(DerivedType &&x)
Definition: manual_constructor.h:147
const BaseType & operator*() const
Definition: manual_constructor.h:120
const BaseType * operator->() const
Definition: manual_constructor.h:117
const BaseType * get() const
Definition: manual_constructor.h:112
void Init()
Definition: manual_constructor.h:123
BaseType * get()
Definition: manual_constructor.h:111
Definition: manual_constructor.h:43
Definition: manual_constructor.h:85
Definition: manual_constructor.h:66
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:92
Round Robin Policy.
Definition: backend_metric.cc:26
DiscoveryMechanismType type
Definition: xds_cluster_resolver.cc:73