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

Detailed Description

Outline

Purpose

Provide meta-function to transform a type to pointer to that type.

Classes

See also
bslmf_removepointer

Description

This component defines a meta-function, bsl::add_pointer, that may be used to transform a type to a pointer to that type.

bsl::add_pointer meets the requirements of the add_pointer template defined in the C++11 standard [meta.trans.ptr].

Usage

In this section we show intended use of this component.

Example 1: Transform Type to Pointer Type to that Type

Suppose that we want to transform a type to a pointer type to that type.

First, we create two typedefs – a pointer type (MyPtrType) and the type pointed to by the pointer type (MyType):

typedef int MyType;
typedef int * MyPtrType;

Now, we transform MyType to a pointer type using bsl::add_pointer and verify that the resulting type is the same as MyPtrType:

assert((bsl::is_same<bsl::add_pointer<MyType>::type, MyPtrType>::value));
BloombergLP::bslmf::AddPointer_Impl< t_TYPE >::type type
Definition bslmf_addpointer.h:175
Definition bslmf_issame.h:146

Finally, if the current compiler supports alias templates C++11 feature, we transform MyType to a pointer type using bsl::add_pointer_t and verify that the resulting type is the same as MyPtrType:

#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
assert((bsl::is_same<bsl::add_pointer_t<MyType>, MyPtrType>::value));
#endif

Note, that the bsl::add_pointer_t avoids the ::type suffix and typename prefix when we want to use the result of the bsl::add_pointer meta-function in templates.