BDE 4.14.0 Production release
|
Macros | |
#define | bslmf_AddReference bslmf::AddReference |
This alias is defined for backward compatibility. | |
Provide a meta-function for adding "reference-ness" to a type.
This component defines a simple template struct
, bslmf::AddReference
, that is used to define a reference type from the type supplied as its single template type parameter. Types that are void
or already reference types are unmodified.
This section illustrates intended use of this component.
First, let us write a simple class that can wrap any other type:
Then, we would like to expose access to the wrapped element through a method that returns a reference to the data member d_data
. However, there would be a problem if the user supplied a parameterized type t_TYPE
that is a reference type, as references-to-references were not permitted by the language (prior the C++11 standard). We can resolve such problems using the meta-function bslmf::AddReference
.
Next, we supply an accessor function, value
, that similarly wraps the parameterized type t_TYPE
with the bslmf::AddReference
meta-function. In this case we must remember to const-quality t_TYPE
before passing it on to the meta-function.
Now, we write a test function, runTest
, to verify our simple wrapper type. We start by wrapping a simple int
value:
Finally, we test Wrapper
with a reference type:
For this example, the associated comments below indicate the expected type of bslmf::AddReference::Type
for a broad range of parameterized types:
#define bslmf_AddReference bslmf::AddReference |