|
BDE 4.39.x Production Release
|
Provide a compile-time check for types convertible to string_view.
Provide a compile-time check for types convertible to string_view.
This component provides a meta-function, bslstl::IsConvertibleToStringView, that may be used to query (at compile-time) whether a type is convertible to a bsl::basic_string_view<CHAR_TYPE, CHAR_TRAITS>.
bslstl::IsConvertibleToStringView meets the requirements of the UnaryTypeTrait concept defined in the C++ standard [meta.rqmts] with a base characteristic of bsl::true_type if the (template parameter) TYPE is convertible to bsl::basic_string_view<CHAR_TYPE, CHAR_TRAITS>, and a base characteristic of bsl::false_type otherwise.
This trait is particularly useful for implementing functions that accept "string-view-like" types, as specified in C++17 and later standards.
In this section we show the intended use of this component.
Suppose that we want to determine whether various types are convertible to bsl::string_view.
First, we note that bsl::string_view itself is convertible:
Next, we verify that const char * is convertible to string_view:
Finally, we verify that an unrelated type is not convertible: