12 #include <type_traits>
15 #include <QStringView>
20 template<
typename Cont>
21 concept
StringViewContainer = std::is_same_v<typename std::decay_t<Cont>::value_type, QStringView>;
26 std::optional<V> Value_;
29 QHash<QString, StringPathTrie> Children_;
31 const std::optional<V>&
GetValue ()
const
38 const auto pos = Children_.find (view.toString ());
39 if (pos == Children_.end ())
45 template<StringViewContainer Cont>
46 void Add (Cont&& path, V value)
48 Add (path.begin (), path.end (), std::move (value));
51 template<
typename It,
typename End>
52 void Add (It begin, End end, V value)
56 Value_ = std::move (value);
60 const auto& strRef = (*begin).toString ();
61 auto pos = Children_.find (strRef);
62 if (pos == Children_.end ())
63 pos = Children_.insert (strRef, {});
64 pos->Add (std::next (begin), end, std::move (value));
72 inline const static StringPathTrie
NullTrie {};
83 std::initializer_list<QStringView> dummy { single };
84 return Find (dummy.begin (), dummy.end ());
87 template<StringViewContainer Cont>
90 return Find (path.begin (), path.end ());
93 template<
typename It,
typename End>
96 return Find (begin, end, {
Value_, end - begin,
this });
99 template<
typename It,
typename End>
103 lastGood = {
Value_, end - begin,
this };
108 const auto& strRef = (*begin).toString ();
109 const auto pos = Children_.find (strRef);
110 if (pos == Children_.end ())
113 return pos->Find (std::next (begin), end, lastGood);