Provide a meta-function to transform pointer type to referent type.
More...
Namespaces |
namespace | bslmf |
namespace | bsl |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a meta-function to transform pointer type to referent type.
-
- Classes:
bsl::remove_pointer | transform a pointer type to its referent pointer |
bsl::remove_pointer_t | alias to the return type of the meta-function |
- See also:
- Component bslmf_addpointer
-
- Description:
- This component defines a meta-function,
bsl::remove_pointer
, that may be used to obtain the type pointed to by a pointer type.
bsl::remove_pointer
and bsl::remove_pointer_t
meet the requirements of the remove_pointer
template defined in the C++11 standard [meta.trans.ptr].
-
- Usage:
- In this section we show intended use of this component.
-
- Example 1: Get the Type Pointed to by a Pointer Type:
- Suppose that we want to get the type pointed to by a pointer type.
- First, we create two
typedef
s -- a pointer type (MyPtrType
) and the type pointed to by the pointer type (MyType
): typedef int MyType;
typedef int *MyPtrType;
Now, we get the type pointed to by MyPtrType
using bsl::remove_pointer
and verify that the resulting type is the same as MyType
: Finally, if the current compiler supports alias templates C++11 feature, we get the type pointed to by MyPtrType
using bsl::remove_pointer_t
and verify that the resulting type is the same as MyType
: #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
assert((bsl::is_same<bsl::remove_pointer_t<MyPtrType>, MyType>::value));
#endif
Note, that the bsl::remove_pointer_t
avoids the ::type
suffix and typename
prefix when we want to use the result of the bsl::remove_pointer
meta-function in templates.