BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_isconvertibletocstring.h
Go to the documentation of this file.
1/// @file bslstl_isconvertibletocstring.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_isconvertibletocstring.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_ISCONVERTIBLETOCSTRING
9#define INCLUDED_BSLSTL_ISCONVERTIBLETOCSTRING
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_isconvertibletocstring bslstl_isconvertibletocstring
15/// @brief Provide a compile-time check for types convertible to C-string.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_isconvertibletocstring
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_isconvertibletocstring-purpose"> Purpose</a>
25/// * <a href="#bslstl_isconvertibletocstring-classes"> Classes </a>
26/// * <a href="#bslstl_isconvertibletocstring-description"> Description </a>
27/// * <a href="#bslstl_isconvertibletocstring-usage"> Usage </a>
28/// * <a href="#bslstl_isconvertibletocstring-example-1-determine-if-a-type-is-convertible-to-a-c-string"> Example 1: Determine If a Type Is Convertible to a C-String </a>
29///
30/// # Purpose {#bslstl_isconvertibletocstring-purpose}
31/// Provide a compile-time check for types convertible to C-string.
32///
33/// # Classes {#bslstl_isconvertibletocstring-classes}
34///
35/// - bslstl::IsConvertibleToCString: meta-function for C-string convertibility
36///
37/// @see bslmf_isconvertible, bslstl_isconvertibletostringview
38///
39/// # Description {#bslstl_isconvertibletocstring-description}
40/// This component provides a meta-function,
41/// `bslstl::IsConvertibleToCString`, that may be used to query (at
42/// compile-time) whether a type is convertible to a C-string (i.e.,
43/// `const CHAR_TYPE *`).
44///
45/// `bslstl::IsConvertibleToCString` meets the requirements of the
46/// `UnaryTypeTrait` concept defined in the C++ standard [meta.rqmts] with a
47/// base characteristic of `bsl::true_type` if the (template parameter) `TYPE`
48/// is convertible to `const CHAR_TYPE *`, and a base characteristic of
49/// `bsl::false_type` otherwise.
50///
51/// ## Usage {#bslstl_isconvertibletocstring-usage}
52///
53///
54/// In this section we show the intended use of this component.
55///
56/// ### Example 1: Determine If a Type Is Convertible to a C-String {#bslstl_isconvertibletocstring-example-1-determine-if-a-type-is-convertible-to-a-c-string}
57///
58///
59/// Suppose that we want to determine whether various types are convertible to
60/// C-strings (null-terminated character arrays).
61///
62/// First, we create a type that is convertible to `const char *`:
63/// @code
64/// struct MyCStringWrapper {
65/// const char *d_str;
66/// operator const char *() const { return d_str; }
67/// };
68/// @endcode
69/// Now, we instantiate the `bslstl::IsConvertibleToCString` template for
70/// various types and verify the results:
71/// @code
72/// assert( (bslstl::IsConvertibleToCString<char, const char *>::value));
73/// assert( (bslstl::IsConvertibleToCString<char, MyCStringWrapper>::value));
74/// assert(!(bslstl::IsConvertibleToCString<char, int>::value));
75/// assert(!(bslstl::IsConvertibleToCString<char, void *>::value));
76/// @endcode
77/// @}
78/** @} */
79/** @} */
80
81/** @addtogroup bsl
82 * @{
83 */
84/** @addtogroup bslstl
85 * @{
86 */
87/** @addtogroup bslstl_isconvertibletocstring
88 * @{
89 */
90
91#include <bslscm_version.h>
92
94#include <bslmf_isconvertible.h>
95
96
97namespace bslstl {
98
99 // ==============================
100 // struct IsConvertibleToCString
101 // ==============================
102
103/// This `struct` template implements a meta-function to determine if the
104/// (template parameter) `t_TYPE` is convertible to `const t_CHAR_TYPE *`.
105template <class t_CHAR_TYPE, class t_TYPE>
107: bsl::is_convertible<t_TYPE, const t_CHAR_TYPE *> {
108};
109
110/// This partial specialization of `IsConvertibleToCString` is instantiated
111/// when `const t_CHAR_TYPE (&)[]` (an unbounded array reference) is tested
112/// for convertibility to `const t_CHAR_TYPE *`. This handles edge cases
113/// with certain compilers where `bsl::is_convertible` may not correctly
114/// handle incomplete array types.
115template <class t_CHAR_TYPE>
116struct IsConvertibleToCString<t_CHAR_TYPE, const t_CHAR_TYPE (&)[]>
117: bsl::true_type {
118};
119
120} // close package namespace
121
122
123#endif
124
125// ----------------------------------------------------------------------------
126// Copyright 2026 Bloomberg Finance L.P.
127//
128// Licensed under the Apache License, Version 2.0 (the "License");
129// you may not use this file except in compliance with the License.
130// You may obtain a copy of the License at
131//
132// http://www.apache.org/licenses/LICENSE-2.0
133//
134// Unless required by applicable law or agreed to in writing, software
135// distributed under the License is distributed on an "AS IS" BASIS,
136// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137// See the License for the specific language governing permissions and
138// limitations under the License.
139// ----------------------------- END-OF-FILE ----------------------------------
140
141/** @} */
142/** @} */
143/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlat_valuetypefunctions.h:939
Definition bslstl_algorithm.h:84
Definition bslmf_isconvertible.h:875
Definition bslstl_isconvertibletocstring.h:107