Skip to content

Update SDK to allow evaluation for more than just boolean flags.#64

Merged
NeaguGeorgiana23 merged 6 commits into
mainfrom
extend_sdk
Feb 19, 2026
Merged

Update SDK to allow evaluation for more than just boolean flags.#64
NeaguGeorgiana23 merged 6 commits into
mainfrom
extend_sdk

Conversation

@NeaguGeorgiana23

Copy link
Copy Markdown
Contributor

This PR

Adds extends the SDK such that it will be able to evaluate flags of type string, int, double and object.

Related Issues

Fixes #63

Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
@NeaguGeorgiana23 NeaguGeorgiana23 requested review from a team as code owners February 5, 2026 14:34
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @NeaguGeorgiana23, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the OpenFeature C++ SDK by extending its capability to evaluate feature flags beyond simple booleans. It introduces support for string, integer, double, and object flag types, making the SDK more versatile for various application requirements. The core change involves a new Value class to handle these diverse data types and corresponding updates to the client API, provider interfaces, and their implementations to facilitate multi-type flag resolution.

Highlights

  • Extended Flag Evaluation Types: The SDK now supports evaluating feature flags for string, integer, double, and object types, in addition to the existing boolean type. This significantly broadens the utility of the SDK for diverse feature flagging needs.
  • New 'Value' Class Introduction: A new Value class has been introduced to serve as a generic return type for structured data from providers. This class uses std::variant to encapsulate various data types (null, boolean, string, integer, double, map, list, datetime), providing a flexible and type-safe mechanism for handling different flag values.
  • Refactored Client API and Provider Interfaces: The ClientAPI has been updated with new GetValue and EvaluateFlag methods for each new type. The FeatureProvider and NoopProvider interfaces and implementations have been extended to include corresponding evaluation methods, ensuring consistency across the SDK.
  • Templated Flag Evaluation Logic: A new templated EvaluateFlag helper function has been added to ClientAPI to streamline the flag evaluation process for different types, reducing code duplication and improving maintainability.
Changelog
  • openfeature/BUILD
    • Added value as a dependency to multiple cc_library targets.
    • Introduced a new cc_library target for the value component.
  • openfeature/client_api.cpp
    • Implemented GetStringValue, GetIntegerValue, GetDoubleValue, and GetObjectValue methods, each with and without an EvaluationContext parameter.
    • Refactored EvaluateBooleanFlag to use a new templated EvaluateFlag helper.
    • Added new EvaluateStringFlag, EvaluateIntegerFlag, EvaluateDoubleFlag, and EvaluateObjectFlag methods.
  • openfeature/client_api.h
    • Declared new public GetStringValue, GetIntegerValue, GetDoubleValue, and GetObjectValue methods.
    • Added declarations for private EvaluateStringFlag, EvaluateIntegerFlag, EvaluateDoubleFlag, EvaluateObjectFlag methods.
    • Introduced a templated EvaluateFlag helper function declaration.
    • Included openfeature/value.h.
  • openfeature/features.h
    • Added pure virtual methods for GetStringValue, GetIntegerValue, GetDoubleValue, and GetObjectValue to the Features interface.
    • Included openfeature/value.h.
  • openfeature/noop_provider.cpp
    • Implemented GetStringEvaluation, GetIntegerEvaluation, GetDoubleEvaluation, and GetObjectEvaluation methods for the NoopProvider, returning default values.
  • openfeature/noop_provider.h
    • Declared new GetStringEvaluation, GetIntegerEvaluation, GetDoubleEvaluation, and GetObjectEvaluation methods in the NoopProvider class.
    • Included openfeature/value.h.
  • openfeature/provider.h
    • Added pure virtual methods for GetStringEvaluation, GetIntegerEvaluation, GetDoubleEvaluation, and GetObjectEvaluation to the FeatureProvider interface.
    • Included openfeature/value.h.
  • openfeature/resolution_details.cpp
    • Updated ResolutionDetails<std::any> to ResolutionDetails<Value>.
  • openfeature/resolution_details.h
    • Included openfeature/value.h.
    • Updated ObjectResolutionDetails to use the new Value type instead of std::any.
  • openfeature/value.cpp
    • New file: Implements the Value class, a std::variant wrapper for various data types.
    • Provides constructors for different types, type-checking methods (e.g., IsNull, IsBool), and type-safe accessors (e.g., AsBool, AsString).
    • Defines operator== and operator!= for Value objects.
  • openfeature/value.h
    • New file: Declares the Value class, its methods, and the InternalVariant type.
  • test/client_api_test.cpp
    • Added new test cases for GetStringValue, GetIntegerValue, GetDoubleValue, and GetObjectValue to verify default value returns from the NoopProvider, both with and without an EvaluationContext.
  • test/mocks/mock_feature_provider.h
    • Added MOCK_METHOD declarations for the new GetStringEvaluation, GetIntegerEvaluation, GetDoubleEvaluation, and GetObjectEvaluation methods.
  • test/noop_provider_test.cpp
    • Added new parameterized tests for StringEvaluation, IntegerEvaluation, and DoubleEvaluation in NoopProviderTest.
    • Added a dedicated test for ObjectEvaluation to ensure correct default value returns.
  • test/resolution_details_test.cpp
    • Added new test cases for StringResolutionDetails, IntResolutionDetails, DoubleResolutionDetails, and ObjectResolutionDetails to verify field access after initialization.
Activity
  • NeaguGeorgiana23 created this pull request to address issue Extend SDK #63, aiming to extend the SDK's flag evaluation capabilities.
  • The changes involve introducing a new Value class and updating various interfaces and implementations across the SDK to support string, integer, double, and object flag types.
  • New test cases have been added to ensure the correct behavior of the new flag evaluation methods and the NoopProvider.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great enhancement, extending the SDK to support evaluation for string, int, double, and object flags. The refactoring in ClientAPI to use a templated EvaluateFlag method is a good improvement to reduce code duplication, and the new Value class provides a flexible way to handle different data types. I've identified a few issues, including some critical bugs in the new Value class that could lead to compilation errors or runtime crashes. I've also noted some areas for improvement regarding dependencies and use of the override specifier. My detailed comments and suggestions are below.

Comment thread openfeature/value.cpp Outdated
Comment thread openfeature/value.cpp Outdated
Comment thread openfeature/value.cpp
Comment thread openfeature/value.cpp Outdated
std::unique_ptr<StringResolutionDetails> ClientAPI::EvaluateStringFlag(
std::string_view flag_key, std::string_view default_value,
const std::optional<EvaluationContext>& ctx) {
std::string default_str(default_value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid creating a temporary std::string from the std::string_view default_value, you can pass default_value directly to EvaluateFlag and construct the std::string inside the lambda. This is slightly more efficient as the string is only constructed if the provider call is actually made.

  return this->EvaluateFlag<StringResolutionDetails>(
      default_value, ctx,
      [&](const std::shared_ptr<FeatureProvider>& provider,
          const EvaluationContext& merged_ctx) {
        return provider->GetStringEvaluation(flag_key, default_value,
                                             merged_ctx);
      });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I implement this change, the generic EvaluateFlag will try to create a ResolutionDetailsType with a std::string_view instead of a std::string as a default_value. This results in a type mismatch error. To make this work, inside EvaluateFlag, I need to check if ResolutionDetailsType is StringResolutionDetails and convert std::string_view to std::string. Do you think this is worth it for the optimization above? If yes, lmk and I'll do the necessary changes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see the templated logic - you can leave it as is

Comment thread openfeature/noop_provider.h Outdated
Comment thread openfeature/value.cpp Outdated
Comment thread openfeature/value.cpp Outdated
Comment thread openfeature/value.cpp Outdated
Comment thread openfeature/value.cpp
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
std::unique_ptr<StringResolutionDetails> ClientAPI::EvaluateStringFlag(
std::string_view flag_key, std::string_view default_value,
const std::optional<EvaluationContext>& ctx) {
std::string default_str(default_value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see the templated logic - you can leave it as is

@NeaguGeorgiana23 NeaguGeorgiana23 merged commit 021f03f into main Feb 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend SDK

3 participants