44#include < optional>
55#include < string>
66#include < unordered_map>
7+ #include < utility>
78#include < vector>
89
910namespace launchdarkly ::server_side::integrations {
@@ -21,6 +22,10 @@ namespace launchdarkly::server_side::integrations {
2122 * A "segment ref" is the string `<segmentKey>.g<generation>`; the SDK
2223 * constructs that string when evaluating a flag and passes it to @ref
2324 * CheckMembership.
25+ *
26+ * Implemented inline because integration libraries link against the
27+ * server-sdk shared library, which only exports the C API — out-of-line
28+ * symbols defined here would not be visible to consumers.
2429 */
2530class Membership {
2631 public:
@@ -29,7 +34,7 @@ class Membership {
2934 * context is included in / excluded from.
3035 *
3136 * If the same segment ref appears in both lists, inclusion wins, matching
32- * the LaunchDarkly Big Segments spec (and the Java/Go SDK behavior) .
37+ * the LaunchDarkly Big Segments spec.
3338 *
3439 * @param included_segment_refs Segment refs the context is explicitly
3540 * included in.
@@ -38,7 +43,18 @@ class Membership {
3843 */
3944 static Membership FromSegmentRefs (
4045 std::vector<std::string> const & included_segment_refs,
41- std::vector<std::string> const & excluded_segment_refs);
46+ std::vector<std::string> const & excluded_segment_refs) {
47+ std::unordered_map<std::string, bool > entries;
48+ // Excluded first so any overlap is overwritten by the included pass;
49+ // inclusion wins per the spec.
50+ for (auto const & ref : excluded_segment_refs) {
51+ entries[ref] = false ;
52+ }
53+ for (auto const & ref : included_segment_refs) {
54+ entries[ref] = true ;
55+ }
56+ return Membership (std::move (entries));
57+ }
4258
4359 /* *
4460 * @brief Returns the membership state for a single segment ref.
@@ -48,10 +64,17 @@ class Membership {
4864 * `std::nullopt` if the segment ref has no entry in this membership.
4965 */
5066 [[nodiscard]] std::optional<bool > CheckMembership (
51- std::string const & segment_ref) const ;
67+ std::string const & segment_ref) const {
68+ auto const it = entries_.find (segment_ref);
69+ if (it == entries_.end ()) {
70+ return std::nullopt ;
71+ }
72+ return it->second ;
73+ }
5274
5375 private:
54- explicit Membership (std::unordered_map<std::string, bool > entries);
76+ explicit Membership (std::unordered_map<std::string, bool > entries)
77+ : entries_(std::move(entries)) {}
5578
5679 // segment-ref → true (included) / false (excluded). Inclusion is the
5780 // stored value when a ref appears in both lists at construction time.
0 commit comments