Quick Links: |
Provide macros for C++11 forward compatibility. More...
BSLS_CPP11_CONSTEXPR | C++11 constexpr keyword |
BSLS_CPP11_DELETED | C++11 = delete function definition |
BSLS_CPP11_EXPLICIT | C++11 explicit for conversion operators |
BSLS_CPP11_FINAL | C++11 final keyword |
BSLS_CPP11_NOEXCEPT | C++11 noexcept keyword |
BSLS_CPP11_NOEXCEPT_AVAILABLE | C++11 noexcept flag |
BSLS_CPP11_NOEXCEPT_SPECIFICATION(...) | C++11 noexcept function qualifier |
BSLS_CPP11_NOEXCEPT_OPERATOR(expr) | C++11 noexcept operation |
BSLS_CPP11_OVERRIDE | C++11 override keyword |
BSLS_CPP11_PROVISIONALLY_FALSE | C++11 specification placeholder |
BSLS_CPP11_CONSTEXPR
: BSLS_KEYWORD_CONSTEXPR
instead. This macro inserts the keyword constexpr
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode.BSLS_CPP11_DELETED
: BSLS_KEYWORD_DELETED
instead. This macro inserts the text = delete
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode.BSLS_CPP11_EXPLICIT
: BSLS_KEYWORD_EXPLICIT
instead. This macro inserts the keyword explicit
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode.BSLS_CPP11_FINAL
: BSLS_KEYWORD_FINAL
instead. This macro inserts the keyword final
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode.BSLS_CPP11_NOEXCEPT
: BSLS_KEYWORD_NOEXCEPT
instead. This macro inserts the keyword noexcept
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode.BSLS_CPP11_NOEXCEPT_AVAILABLE
: BSLS_KEYWORD_NOEXCEPT_AVAILABLE
instead. This macro expands to true
when the noexcept
feature is available and false
otherwise.BSLS_CPP11_NOEXCEPT_SPECIFICATION(BOOL_EXPRESSION)
: BSLS_KEYWORD_NOEXCEPT_SPECIFICATION
instead. This macro inserts the exception specification noexcept(BOOL_EXPRESSION)
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode. This macro is used to specify which version of noexcept
is intended when multiple noexcept
s are used in a single statement.BSLS_CPP11_NOEXCEPT_OPERATOR(expr)
: BSLS_KEYWORD_NOEXCEPT_OPERATOR
instead. This macro inserts the operation noexcept(expr)
when compiling with C++11 mode and inserts the literal false
when compiling with C++03 mode.BSLS_CPP11_OVERRIDE
DEPRECATED: Use BSLS_KEYWORD_OVERRIDE
instead. This macro inserts the keyword override
when compiling with C++11 mode and inserts nothing when compiling with C++03 mode.BSLS_CPP11_PROVISIONALLY_FALSE
: false
instead. This macro inserts the keyword false
. This macro is intended to be used as a placeholder in the BSLS_CPP11_NOEXCEPT_SPECIFICATION(BOOL_EXPRESSION)
macro when traits needed for BOOL_EXPRESSION
have not yet been implemented.explicit
keyword to indicate that constructors taking just one argument are not considered for implicit conversions. Instead, they can only be used for explicit conversions. C++ also provides the ability to define conversion operators but prior to C++11 these conversion operators are considered for implicit conversion. C++11 allows the use of the explicit
keyword with conversion operators to avoid its use for implicit conversions. The macro BSLS_CPP11_EXPLICIT
can be used to mark conversions as explicit conversions which will be checked when compiling with C++11 mode. For example, an Optional
type may have an explicit conversion to bool
to indicate that the value is set (note the conversion operator): template <class TYPE> class Optional { TYPE* d_value; public: Optional(): d_value() {} explicit Optional(const TYPE& value): d_value(new TYPE(value)) {} ~Optional() { delete d_value; } // ... BSLS_CPP11_EXPLICIT operator bool() const { return d_value; } };
Optional
class in a condition it is desirable that it converts to a bool
: Optional<int> value; if (value) { /*... */ }
bool flag = value;
bool
for code which needs to compile with C++03 mode the conversion operator should convert to a member pointer type instead: doing so has a similar effect to making the conversion operator explicit
. final
keyword after the class name in the class definition to label classes which are not intended to be derived from. The macro BSLS_CPP11_FINAL
is replaced by final
when compiling with C++11 causing the compiler to enforce that a class can't be further derived. The code below defines a class which can't be derived from: class FinalClass BSLS_CPP11_FINAL { int d_value; public: explicit FinalClass(int value = 0): d_value(value) {} int value() const { return d_value; } };
class FinalClassDerived: public FinalClass { int d_anotherValue; public: explicit FinalClassDerived(int value) : d_anotherValue(2 * value) { } int anotherValue() const { return d_anotherValue; } };
final
. The macro BSLS_CPP11_FINAL
can also be used for this purpose. To demonstrate the use of this keyword first a base class with a virtual
function is defined: struct FinalFunctionBase { virtual int f() { return 0; } };
f
can be marked as the final overrider using BSLS_CPP11_FINAL
: struct FinalFunctionDerived: FinalFunctionBase { int f() BSLS_CPP11_FINAL { return 1; } };
f
, i.e., the following code will result in an error when compiling with C++11 mode: struct FinalFunctionFailure: FinalFunctionDerived { int f() { return 2; } };
override
is used to identify functions overriding a virtual
function from a base class. If a function identified as override
does not override a virtual
function from a base class the compilation results in an error. The macro BSLS_CPP11_OVERRIDE
is used to insert the override
keyword when compiling with C++11 mode. When compiling with C++03 mode it has no effect but it both cases it documents that a function is overriding a virtual
function from a base class. To demonstrate the use of the BSLS_CPP11_OVERRIDE
macro first a base class is defined: struct OverrideBase { virtual int f() const { return 0; } };
OverrideBase::f
in a derived class the BSLS_CPP11_OVERRIDE
macro should be used to ascertain that the function in the derived class is indeed overriding a virtual
function: struct OverrideSuccess: OverrideBase { int f() const BSLS_CPP11_OVERRIDE { return 1; } };
const
in the function declaration): struct OverrideFailure: OverrideBase { int f() BSLS_CPP11_OVERRIDE { return 2; } };