Commit ab479290 authored by Ing. Jan Trávníček's avatar Ing. Jan Trávníček

abstraction: limit type qualifiers interface

parent cbfe143d
......@@ -14,20 +14,21 @@ public:
RREF = 0x4,
};
friend constexpr TypeQualifierSet operator | ( TypeQualifierSet first, TypeQualifierSet second ) {
return static_cast < TypeQualifierSet > ( static_cast < unsigned > ( first ) | static_cast < unsigned > ( second ) );
}
friend constexpr TypeQualifierSet operator & ( TypeQualifierSet first, TypeQualifierSet second ) {
return static_cast < TypeQualifierSet > ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) );
private:
static constexpr bool is ( TypeQualifierSet first, TypeQualifierSet second ) {
return ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) ) == static_cast < unsigned > ( second );
}
friend constexpr bool operator && ( TypeQualifierSet first, TypeQualifierSet second ) {
return ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) ) == static_cast < unsigned > ( second );
public:
friend constexpr TypeQualifierSet operator | ( TypeQualifierSet first, TypeQualifierSet second ) {
unsigned res = static_cast < unsigned > ( first ) | static_cast < unsigned > ( second );
if ( is ( static_cast < TypeQualifierSet > ( res ), TypeQualifiers::TypeQualifierSet::RREF ) && is ( static_cast < TypeQualifierSet > ( res ), TypeQualifiers::TypeQualifierSet::LREF ) )
res &= ~ static_cast < unsigned > ( TypeQualifiers::TypeQualifierSet::RREF ); // decay LREF and RREF to LREF
return static_cast < TypeQualifierSet > ( res );
}
static constexpr bool isConst ( TypeQualifierSet arg ) {
return arg && TypeQualifiers::TypeQualifierSet::CONST;
return is ( arg, TypeQualifiers::TypeQualifierSet::CONST );
}
static constexpr bool isRef ( TypeQualifierSet arg ) {
......@@ -35,11 +36,11 @@ public:
}
static constexpr bool isRvalueRef ( TypeQualifierSet arg ) {
return arg && TypeQualifiers::TypeQualifierSet::RREF;
return is ( arg, TypeQualifiers::TypeQualifierSet::RREF );
}
static constexpr bool isLvalueRef ( TypeQualifierSet arg ) {
return arg && TypeQualifiers::TypeQualifierSet::LREF;
return is ( arg, TypeQualifiers::TypeQualifierSet::LREF );
}
template < class Type >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment