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

Macros

#define bslmf_RemoveCvq   bslmf::RemoveCvq
 This alias is defined for backward compatibility.
 

Detailed Description

Outline

Purpose

Provide a meta-function for removing const/volatile qualifiers.

Classes

Description

This component defines a simple template structure used to strip of any top-level const/volatile qualifiers from it's single template parameter. The un-qualified type can be accessed via the Type member defined in bslmf::RemoveCvq.

struct MyType {};
bsl::remove_cv< t_TYPE >::type Type
Definition bslmf_removecvq.h:147

Usage

We can make a simple template function that shows whether two objects are the same type, ignoring const and volatile qualifiers.

First, we create a template that will determine whether two objects are EXACTLY the same type:

template <class t_TYPE>
bool isSame(t_TYPE& a, t_TYPE& b) { return true; }
template <class TYPEA, class TYPEB>
bool isSame(TYPEA& a, TYPEB& b) { return false; }

Next, we combine that template function with the use of bslmf::RemoveCvq to create a template that will determine whether two objects are the same type, ignoring const and volatile qualifiers:

template <class TYPEA, class TYPEB>
bool isSortaSame(TYPEA& a, TYPEB& b)
{
return isSame(aa, bb);
}

Next, we use the templates

int i = 0, j = 0;
const int ci = 0, cj = 0;
volatile int vi = 0, vj = 0;
const volatile int cvi = 0, cvj = 0;
double x = 0, y = 0;
assert( isSame(i, j));
assert( isSame(ci, cj));
assert( isSame(vi, vj));
assert( isSame(cvi, cvj));
assert( isSame(x, y));
assert(! isSame(i, x));
assert(! isSame(i, ci));
assert(! isSame(i, vi));
assert(! isSame(i, cvi));
assert(! isSame(ci, vi));
assert(! isSame(ci, cvi));
assert(! isSame(vi, cvi));
assert(! isSortaSame(i, x));
assert( isSortaSame(i, ci));
assert( isSortaSame(i, vi));
assert( isSortaSame(i, cvi));
assert( isSortaSame(ci, vi));
assert( isSortaSame(ci, vi));
assert( isSortaSame(ci, cvi));
assert( isSortaSame(vi, cvi));

Macro Definition Documentation

◆ bslmf_RemoveCvq

#define bslmf_RemoveCvq   bslmf::RemoveCvq