C++ Server-Side SDK
LaunchDarkly SDK
evaluation_detail.hpp
1 #pragma once
2 
3 #include <cstddef>
4 #include <optional>
5 
6 #include <launchdarkly/data/evaluation_reason.hpp>
7 
8 namespace launchdarkly {
9 
17 template <typename T>
19  public:
27  std::optional<std::size_t> variation_index,
28  std::optional<EvaluationReason> reason);
29 
37  T default_value);
38 
45 
50  [[nodiscard]] T const& Value() const;
51 
56  [[nodiscard]] std::optional<std::size_t> VariationIndex() const;
57 
61  [[nodiscard]] bool IsError() const;
62 
66  [[nodiscard]] std::optional<EvaluationReason> const& Reason() const;
67 
71  T const& operator*() const;
72 
73  private:
74  T value_;
75  std::optional<std::size_t> variation_index_;
76  std::optional<EvaluationReason> reason_;
77 };
78 
79 /*
80  * Holds details for the C bindings, omitting the generic type parameter
81  * that is needed for EvaluationDetail<T>. Instead, the bindings will
82  * directly return the evaluation result, and fill in a detail structure
83  * using an out parameter.
84  */
86  template <typename T>
88  : variation_index(detail.VariationIndex()), reason(detail.Reason()) {}
89  std::optional<std::size_t> variation_index;
90  std::optional<EvaluationReason> reason;
91 };
92 
93 } // namespace launchdarkly
Definition: evaluation_detail.hpp:18
std::optional< EvaluationReason > const & Reason() const
Definition: evaluation_detail.cpp:34
std::optional< std::size_t > VariationIndex() const
Definition: evaluation_detail.cpp:39
T const & operator*() const
Definition: evaluation_detail.cpp:43
EvaluationDetail(T value, std::optional< std::size_t > variation_index, std::optional< EvaluationReason > reason)
T const & Value() const
Definition: evaluation_detail.cpp:29
bool IsError() const
Definition: evaluation_detail.cpp:48
Definition: evaluation_reason.hpp:13
ErrorKind
Definition: evaluation_reason.hpp:39
Definition: evaluation_detail.hpp:85