Add std::string_view constructor to hashed_string#1334
Open
skhaz wants to merge 1 commit into
Open
Conversation
ce4b04f to
f53f620
Compare
Adds a convenience constructor accepting std::string_view directly,
eliminating the need for manual .data() and .size() calls.
Implementation uses SFINAE to exclude C-string pointers, avoiding
ambiguity with the const_wrapper constructor used by UDL operators.
Zero overhead: single conversion to string_view, then direct delegation
to the existing (ptr, len) constructor.
Example:
// Before: verbose
auto hs = entt::hashed_string{sv.data(), sv.size()};
// After: clean
auto hs = entt::hashed_string{sv};
Related: PR skypjack#824 (mentioned string_view as desirable)
f53f620 to
4276b40
Compare
Author
|
Any chance to get a review on this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a convenience constructor accepting
std::string_viewdirectly, eliminating the need for manual.data()and.size()calls.Motivation
As noted in PR #824,
std::string_viewsupport was mentioned as desirable but not included at the time. This PR addresses that gap.Many codebases use
std::string_viewextensively, and users currently write verbose code:Implementation
Zero overhead: Single conversion to
string_view, then direct delegation.SFINAE constraint: Excludes C-string pointers to avoid ambiguity with
const_wrapperused by UDL operators (_hs,_hws).Test Coverage
string_viewstring_view(prefixes)string_viewstring_viewwith embedded nullsChecklist
Related
view.data(), view.size()pattern/cc @skypjack