4 #include <launchdarkly/error.hpp>
6 #include <tl/expected.hpp>
12 namespace launchdarkly::detail {
13 template <
typename T,
typename =
void>
19 template <
typename T,
typename ReturnType,
typename =
void>
22 template <
typename T,
typename ReturnType>
25 std::void_t<decltype(std::declval<T>().Build())>>
26 : std::integral_constant<
28 std::is_same_v<decltype(std::declval<T>().Build()), ReturnType>> {};
40 template <
typename Builder,
typename OpaqueBuilder,
typename OpaqueResult>
41 LDStatus ConsumeBuilder(OpaqueBuilder opaque_builder,
42 OpaqueResult* out_result) {
44 tl::expected<typename Builder::Result, launchdarkly::Error>;
47 "Builder must have an associated type named Result");
51 "Builder must have a Build method that returns "
52 "tl::expected<typename Builder::Result, launchdarkly::Error>");
54 auto builder =
reinterpret_cast<Builder*
>(opaque_builder);
56 tl::expected<typename Builder::Result, launchdarkly::Error> res =
62 *out_result =
nullptr;
63 return reinterpret_cast<LDStatus
>(
new launchdarkly::Error(res.error()));
66 *out_result =
reinterpret_cast<OpaqueResult
>(
67 new typename Builder::Result(std::move(res.value())));
72 template <
typename OptType,
typename OutResult>
73 bool OptReturn(std::optional<OptType>
const& opt, OutResult* out_param) {
81 template <
typename OptType,
typename OutResult>
82 bool OptReturnStaticCast(std::optional<OptType>
const& opt,
83 OutResult* out_param) {
85 *out_param =
static_cast<OutResult
>(*opt);
91 template <
typename OptType,
typename OutResult>
92 bool OptReturnReinterpretCast(std::optional<OptType>& opt,
93 OutResult* out_param) {
95 *out_param =
reinterpret_cast<OutResult
>(&(opt.value()));
103 #ifdef LAUNCHDARKLY_USE_ASSERT
104 #define LD_ASSERT(cond) assert(cond)
106 #define LD_ASSERT(cond)
109 #define LD_ASSERT_NOT_NULL(param) LD_ASSERT(param != nullptr)
Definition: c_binding_helpers.hpp:20
Definition: c_binding_helpers.hpp:14