44#include < iterator>
55#include < optional>
66#include < string>
7+ #include < string_view>
78#include < utility>
89
910#include < rpc.h>
@@ -77,29 +78,29 @@ GuidToString(const GUID& guid)
7778}
7879
7980/* *
80- * @brief Parses a string for a GUID and returns it, if valid.
81+ * @brief Parses a string (_view) for a GUID and returns it, if valid.
8182 *
82- * @tparam TString The type of input string to parse.
83- * @param input The string to parse.
83+ * @tparam TStringView The type of input string view to parse.
84+ * @param input The string view to parse.
8485 * @return std::optional<GUID> An optional containing a GUID if the input was valid, std::nullopt otherwise.
8586 */
86- template <typename TString >
87+ template <typename TStringView >
8788inline std::optional<GUID>
88- GuidFromString ( const TString& input) noexcept ;
89+ GuidFromStringView (TStringView input) noexcept ;
8990
9091/* *
91- * @brief Specialization for parsing a GUID from std::string .
92+ * @brief Specialization for parsing a GUID from std::string_view .
9293 *
9394 * @tparam TString std::string
9495 * @param input
9596 * @return std::optional<GUID>
9697 */
9798template <>
9899inline std::optional<GUID>
99- GuidFromString ( const std::string& input) noexcept
100+ GuidFromStringView ( std::string_view input) noexcept
100101{
101102 GUID guid{};
102- auto result = UuidFromStringA (reinterpret_cast <RPC_CSTR>(const_cast <std::string ::value_type*>(std::data (input))), &guid);
103+ auto result = UuidFromStringA (reinterpret_cast <RPC_CSTR>(const_cast <std::string_view ::value_type*>(std::data (input))), &guid);
103104 if (result != NOERROR) {
104105 return std::nullopt ;
105106 }
@@ -108,24 +109,63 @@ GuidFromString(const std::string& input) noexcept
108109}
109110
110111/* *
111- * @brief Specialization for parsing a GUID from std::wstring .
112+ * @brief Specialization for parsing a GUID from std::wstring_view .
112113 *
113114 * @tparam TString std::wstring
114115 * @param input
115116 * @return std::optional<GUID>
116117 */
117118template <>
118119inline std::optional<GUID>
119- GuidFromString ( const std::wstring& input) noexcept
120+ GuidFromStringView ( std::wstring_view input) noexcept
120121{
121122 GUID guid{};
122- auto result = UuidFromStringW (reinterpret_cast <RPC_WSTR>(const_cast <std::wstring ::value_type*>(std::data (input))), &guid);
123+ auto result = UuidFromStringW (reinterpret_cast <RPC_WSTR>(const_cast <std::wstring_view ::value_type*>(std::data (input))), &guid);
123124 if (result != NOERROR) {
124125 return std::nullopt ;
125126 }
126127
127128 return guid;
128129}
130+
131+ /* *
132+ * @brief Parses a string for a GUID and returns it, if valid.
133+ *
134+ * @tparam TString The type of input string to parse.
135+ * @param input The string to parse.
136+ * @return std::optional<GUID> An optional containing a GUID if the input was valid, std::nullopt otherwise.
137+ */
138+ template <typename TString>
139+ inline std::optional<GUID>
140+ GuidFromString (const TString& input) noexcept ;
141+
142+ /* *
143+ * @brief Specialization for parsing a GUID from std::string.
144+ *
145+ * @tparam TString std::string
146+ * @param input
147+ * @return std::optional<GUID>
148+ */
149+ template <>
150+ inline std::optional<GUID>
151+ GuidFromString (const std::string& input) noexcept
152+ {
153+ return GuidFromStringView (std::string_view{ input });
154+ }
155+
156+ /* *
157+ * @brief Specialization for parsing a GUID from std::wstring.
158+ *
159+ * @tparam TString std::wstring
160+ * @param input
161+ * @return std::optional<GUID>
162+ */
163+ template <>
164+ inline std::optional<GUID>
165+ GuidFromString (const std::wstring& input) noexcept
166+ {
167+ return GuidFromStringView (std::wstring_view{ input });
168+ }
129169} // namespace notstd
130170
131171namespace std
0 commit comments