BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_isconvertibletostringview

Detailed Description

Provide a compile-time check for types convertible to string_view.

Outline

Purpose

Provide a compile-time check for types convertible to string_view.

Classes

See also
bslmf_isconvertible, bslstl_isconvertibletocstring, bslstl_stringview

Description

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.

Usage

In this section we show the intended use of this component.

Example 1: Determine If a Type Is Convertible to a String View

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:

std::char_traits<char>,
bsl::string_view>::value));
Definition bslstl_stringview.h:471
Definition bslstl_isconvertibletostringview.h:118

Next, we verify that const char * is convertible to string_view:

std::char_traits<char>,
const char *>::value));

Finally, we verify that an unrelated type is not convertible:

std::char_traits<char>,
int>::value));