BDE 4.14.0 Production release
|
Macros | |
#define | bslmf_IsArray bslmf::IsArray |
This alias is defined for backward compatibility. | |
Provide a compile-time check for array types.
is_array
meta-functionis_bounded_array
meta-functionis_unbounded_array
meta-functionThis component defines four meta-functions, – bsl::is_array
, bsl::is_bounded_array
, bsl::is_unbounded_array
, and BloombergLP::bslmf::IsArray
and three template variables, – bsl::is_array_v
, bsl::is_bounded_array_v
, and bsl::is_unbounded_array_v
– that contain the result values of the corresponding meta-functions. The is_array
meta-functions may be used to query whether a type is an array type, while the is_bounded_array
meta-functions may be used to query whether a type is an array of known bound, and the is_unbounded_array
meta-functions may be used to query whether a type is an array of unknown bound.
bsl::is_array
meets the requirements of the is_array
template defined in the C++11 standard [meta.unary.cat], while bslmf::IsArray
was devised before is_array
was standardized. The two meta-functions are functionally equivalent. The major difference between them is that the result for bsl::is_array
is indicated by the class member value
, while the result for bslmf::IsArray
is indicated by the class member value
.
Note that bsl::is_array
should be preferred over bslmf::IsArray
, and in general, should be used by new components.
bsl::is_bounded_array
and bsl::is_bounded_array
meet the requirements of the is_bounded_array
and is_unbounded_array
template defined in the C++20 standard [meta.unary.prop].
Also note that the template variables is_array_v
, is_bounded_array_v
, and is_unbounded_array_v
are defined in the standard as inline variables. If the current compiler supports the inline variable C++17 compiler feature, these variables are defined as inline constexpr bool
variables. Otherwise, if the compiler supports the variable templates C++14 compiler feature, these variables are defined as non-inline constexpr bool
variables. See BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES
and BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
macros in the bsls_compilerfeatures component for details.
In this section we show intended use of this component.
Suppose that we want to assert whether a particular type is an array type.
First, we create three typedef
s – a non-array type, an array type with a known bound, and an array type and an array type with an unknown bound:
Now, we instantiate each of the the meta-functions for each of the typedef
s and assert the value
static data member of each instantiation:
Note that if the current compiler supports the variable templates C++14 feature then we can re-write the snippet of code above using the bsl::is_array_v
variable as follows:
#define bslmf_IsArray bslmf::IsArray |