This component-private utility struct
provides a namespace for the flatten
overload set intended to be used in concert with an overload set consisting of a function template with a deduced argument and an non-template overload accepting a const char *
. The actual implementation of the functionality would be in the const char *
overload whereas the purpose of the function template is to invoke the const char *
overload with a null-terminated string.
The function template achieves null-termination by recursively calling the function and supplying it with the result of flatten
invoked on the deduced argument. This flatten
invocation will call c_str()
on various supported string
types, will produce a temporary bsl::string
for possibly non-null-terminated bslstl::StringRef
, and will result in a BSLMF_ASSERT
for any unsupported type. Calling the function with the temporary bsl::string
produced from bslstl::StringRef
will result in a second invocation of flatten
, this time producing const char *
, and finally calling the function with a null-terminated string.
Note that the bslstl::StringRef
overload for flatten
is provided for backwards compatibility. Without it, the bsl::string
and std::string
overloads would be ambiguous. In new code, it is preferable to not provide bslstl::StringRef
overload in a similar facility and require the clients to explicitly state the string type in their code, making a potential allocation obvious. The bsl::string_view
overload is not provided for the same reason.
Also note that since the constructor for string
types from bsl::string_view
is explicit, it is not necessary to support bsl::string_view
for backwards compatibility, and it is not supported.