BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_iscopyconstructible

Detailed Description

Outline

Purpose

Provide a meta-function to report if a type is copy constructible.

Classes

See also
bslmf_integralconstant, bslmf_nestedtraitdeclaration

Description

This component defines a meta-function, bsl::is_copy_constructible and a template variable bsl::is_copy_constructible_v, that represents the result value of the bsl::is_copy_constructible meta-function, that may be used to query whether a type is copy constructible.

bsl::is_copy_constructible has the same syntax as the is_copy_constructible template from the C++11 standard [meta.unary.prop]. Indeed, in C++11 compilation environments, bsl::is_copy_constructible simply forwards to the native implementation, which can determine the correct value for all types without requiring specialization; in C++03 environments, bsl::is_copy_construcible provides welcome backward compatibility but returns true for all user-defined types and requires explicit specialization for types that are not copy constructible (e.g., move-only types).

Note that the bsl::is_copy_constructible trait cannot be declared as a nested trait because the default value of the trait is true and nested traits work properly only for traits that have default value false. In order to indicate that a certain type T is not copy constructible, the following idiom should be used:

namespace bsl {
template <>
struct is_copy_constructible<T> : false_type { };
}
Definition bdlb_printmethods.h:283
integral_constant< bool, false > false_type
Definition bslmf_integralconstant.h:297

Also note that the template variable is_copy_constructible_v is defined in the C++17 standard as an inline variable. If the current compiler supports the inline variable C++17 compiler feature, bsl::is_copy_constructible_v is defined as an inline constexpr bool variable. Otherwise, if the compiler supports the variable templates C++14 compiler feature, bsl::is_copy_constructible_v is defined as a non-inline constexpr bool variable. See BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES and BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES macros in bsls_compilerfeatures component for details.