File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -618,7 +618,14 @@ constexpr bool FastStringKey::operator==(const FastStringKey& other) const {
618
618
return name_ == other.name_ ;
619
619
}
620
620
621
- constexpr FastStringKey::FastStringKey (std::string_view name)
621
+ consteval FastStringKey::FastStringKey (std::string_view name)
622
+ : FastStringKey(name, 0 ) {}
623
+
624
+ constexpr FastStringKey FastStringKey::AllowDynamic (std::string_view name) {
625
+ return FastStringKey (name, 0 );
626
+ }
627
+
628
+ constexpr FastStringKey::FastStringKey (std::string_view name, int dummy)
622
629
: name_(name), cached_hash_(HashImpl(name)) {}
623
630
624
631
constexpr std::string_view FastStringKey::as_string_view () const {
Original file line number Diff line number Diff line change @@ -822,7 +822,11 @@ class PersistentToLocal {
822
822
// computations.
823
823
class FastStringKey {
824
824
public:
825
- constexpr explicit FastStringKey (std::string_view name);
825
+ // consteval ensures that the argument is a compile-time constant.
826
+ consteval explicit FastStringKey (std::string_view name);
827
+ // passing something that is not a compile-time constant needs explicit
828
+ // opt-in via this helper, as it defeats the purpose of FastStringKey.
829
+ static constexpr FastStringKey AllowDynamic (std::string_view name);
826
830
827
831
struct Hash {
828
832
constexpr size_t operator ()(const FastStringKey& key) const ;
@@ -832,6 +836,8 @@ class FastStringKey {
832
836
constexpr std::string_view as_string_view () const ;
833
837
834
838
private:
839
+ constexpr explicit FastStringKey (std::string_view name, int dummy);
840
+
835
841
static constexpr size_t HashImpl (std::string_view str);
836
842
837
843
const std::string_view name_;
You can’t perform that action at this time.
0 commit comments