Skip to content

Accept std::string_view in rfl::string_to_enum - #802

Open
clockblocker wants to merge 1 commit into
munich-data-engineering:mainfrom
clockblocker:enum-string-view
Open

clockblocker wants to merge 1 commit into
munich-data-engineering:mainfrom
clockblocker:enum-string-view

Conversation

@clockblocker

Copy link
Copy Markdown
Contributor

Summary

Updates rfl::string_to_enum and rfl::internal::enums::from_string (both C++20 and C++26 paths) to accept std::string_view instead of const std::string&, avoiding unnecessary string copies and heap allocations.

Closes #565

Details

  • Updated rfl::string_to_enum, rfl::internal::enums::from_string, cpp20::from_string, and cpp26::from_string to accept std::string_view.
  • Replaced std::stoi in the numeric fallback with allocation-free, exception-free std::from_chars enforcing full-string consumption (ec == std::errc{} && ptr == end), supporting wide/unsigned underlying types (int64_t, uint32_t, uint64_t, bool) while preserving existing narrow-enum behavior.
  • Replaced rfl::internal::strings::split with zero-allocation std::string_view slicing on '|' for flag enums.
  • Added unit tests in tests/generic/test_string_to_enum.cpp covering std::string_view literals, non-null-terminated substrings, flag enums, numeric fallback edge cases, enum_names_only = true, and const char* / std::string callers.

Verification

  • ctest -R "(enum|Enum)": 40/40 PASSED (reflect-cpp-generic-tests + reflect-cpp-json-tests: 424/424 PASSED under -Wall -Werror).
  • Standalone header compile checks (-Wall -Wextra -Werror) on all 4 modified headers: PASSED.

This branch has not been deployed

No deployments
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.

string_to_enum does not support std::string_view

1 participant