From cd7e0531c0928bc61f8c4a56ee4747f214100d3c Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 13 Feb 2024 10:40:57 -0500 Subject: Change ll_convert(string) to just ll_convert(string). As a function parameter, an assignment expression or a `return` expression, `ll_convert()` can infer its target type. When it's important to specify the TOTYPE explicitly, rename the old `ll_convert()` function template to `ll_convert_to()`. Fix existing usage. --- indra/llcommon/llstring.h | 39 +++++++++++++++++++++++++++++++++------ indra/llcommon/stringize.h | 6 +++--- 2 files changed, 36 insertions(+), 9 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index b43093fbfc..dbd60bc9c7 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -516,9 +516,36 @@ struct ll_convert_impl TO operator()(const FROM& in) const; }; -// Use a function template to get the nice ll_convert(from_value) API. +/** + * somefunction(ll_convert(data)) + * target = ll_convert(data) + * totype otherfunc(const fromtype& data) + * { + * // ... + * return ll_convert(data); + * } + * all infer both the FROM type and the TO type. + */ +template +class ll_convert +{ +private: + const FROM& mRef; + +public: + ll_convert(const FROM& ref): mRef(ref) {} + + template + inline operator TO() const + { + return ll_convert_impl()(mRef); + } +}; + +// When the TO type must be explicit, use a function template to get +// ll_convert_to(from_value) API. template -TO ll_convert(const FROM& in) +TO ll_convert_to(const FROM& in) { return ll_convert_impl()(in); } @@ -574,8 +601,8 @@ inline size_t ll_convert_length (const char* zstr) { return std::strl // and longname(const string&, len) so calls written pre-ll_convert() will // work. Most of these overloads will be unified once we turn on C++17 and can // use std::string_view. -// It also uses aliasmacro to ensure that both ll_convert(const char*) -// and ll_convert(const string&) will work. +// It also uses aliasmacro to ensure that both ll_convert(const char*) +// and ll_convert(const string&) will work. #define ll_convert_forms(aliasmacro, OUTSTR, INSTR, longname) \ LL_COMMON_API OUTSTR longname(const INSTR::value_type* in, size_t len); \ inline auto longname(const INSTR& in, size_t len) \ @@ -807,7 +834,7 @@ LL_COMMON_API std::string ll_convert_string_to_utf8_string(const std::string& in template STRING windows_message(unsigned long error) { - return ll_convert(windows_message(error)); + return ll_convert(windows_message(error)); } /// There's only one real implementation @@ -1780,7 +1807,7 @@ auto LLStringUtilBase::getoptenv(const std::string& key) -> boost::optional(*found) }; + return { ll_convert_to(*found) }; } else { diff --git a/indra/llcommon/stringize.h b/indra/llcommon/stringize.h index c0b13135f9..63d44a7272 100644 --- a/indra/llcommon/stringize.h +++ b/indra/llcommon/stringize.h @@ -88,13 +88,13 @@ struct gstringize_impl }; // partially specialize for a single STRING argument - -// note that ll_convert(T) already handles the trivial case +// note that ll_convert_to(T) already handles the trivial case template struct gstringize_impl> { auto operator()(const std::basic_string& arg) { - return ll_convert>(arg); + return ll_convert_to>(arg); } }; @@ -105,7 +105,7 @@ struct gstringize_impl { auto operator()(const INCHAR* arg) { - return ll_convert>(arg); + return ll_convert_to>(arg); } }; -- cgit v1.2.3