|
0.12.0
|
|
Freundlich's C++ toolkit |
Documents smaller features that do not warrant their own modules.
Classes | |
| struct | fcppt::null_ptr_t |
| A class that is implicitly convertible to null pointers. More... | |
Macros | |
| #define | FCPPT_ASSERT_COMPLETE(type) |
| Assert at compile time that a type is complete. | |
| #define | FCPPT_FOREACH_ENUMERATOR(name, enum_) |
| Iterates over an enum. | |
| #define | FCPPT_FOREACH_ENUMERATOR_START(name, enum_, start) |
| Iterates over an enum with a designated start. | |
| #define | FCPPT_FOREACH_ENUMERATOR_START_END(name, enum_, start, end) |
| Iterates over an enum with designated start and end values. | |
| #define | FCPPT_NONASSIGNABLE(classname) |
| Makes a class nonassignable. | |
| #define | FCPPT_NONCOPYABLE(classname) |
| Makes a class noncopyable. | |
| #define | FCPPT_SAFE_BOOL(classname) |
| Implements the safe bool idiom for a class. | |
| #define | FCPPT_STATIC_ASSERT_EXPRESSION(cond) |
| Assert at compile time that a condition is true, using an expression. | |
| #define | FCPPT_STATIC_ASSERT_STATEMENT(cond) |
| Assert at compile time that a condition is true, using a statement. | |
Functions | |
| fcppt::null_ptr_t const | fcppt::null_ptr () |
| Partial replacement for C++11's nullptr. | |
| #define FCPPT_ASSERT_COMPLETE | ( | type | ) |
Assert at compile time that a type is complete.
In some cases, a type must be complete, which bascially means that it is not void and if it is a class, the definition must already be known. For example, delete has undefined behaviour if it is invoked on a type that is not complete but has a non trivial destructor.
This macro generates a compile time error if a type is not complete. An example of its usage is shown below.
| #define FCPPT_FOREACH_ENUMERATOR | ( | name, | |
| enum_ | |||
| ) |
Iterates over an enum.
Iterates over the type enum_::type, giving the loop variable the name name, starting at static_cast<enum_::type>(0) and ending before enum_::size (which means that enum_::size is not included).
This macro generates a for loop that hides some enum casting behind its scenes. It is important that the enumerators in the enum are contiguous as in the following example:
| #define FCPPT_FOREACH_ENUMERATOR_START | ( | name, | |
| enum_, | |||
| start | |||
| ) |
Iterates over an enum with a designated start.
Iterates over the type enum_::type, giving the loop variable the name name, starting at the enumerator start and ending before enum_::size (which means that enum_::size is not included).
This macro generates a for loop that hides some enum casting behind its scenes. It is important that the enumerators in the enum are contiguous as in the following example:
| #define FCPPT_FOREACH_ENUMERATOR_START_END | ( | name, | |
| enum_, | |||
| start, | |||
| end | |||
| ) |
Iterates over an enum with designated start and end values.
Iterates over the type enum_::type, giving the loop variable the name name, starting at the enumerator start and ending before end (which means end itself is not included).
This macro generates a for loop that hides some enum casting behind its scenes. It is important that the enumerators in the enum are contiguous as in the following example:
| #define FCPPT_NONASSIGNABLE | ( | classname | ) |
Makes a class nonassignable.
Makes the class called classname nonassignable. The macro must be placed inside the class definition and called with the name of the class. It makes the assignment operator inaccessible.
Often, classes are not assignable but copyable, for example when they contain constant elements or references. To make it clear to the compiler and to the users of the class that it should not be possible to assign it, this macro should be used.
| classname | The name of the class |
| #define FCPPT_NONCOPYABLE | ( | classname | ) |
Makes a class noncopyable.
Makes the class called classname noncopyable. The macro must be placed inside the class definition and called with the name of the class. It makes the copy constructor and the assignment operator inaccessible.
By default, C++ generates a copy constructor and assignment operator for every class where this is possible (when its elements can all be copy constructed and assigned). However, this is not a good default in a lot of situations where it can be dangerous to copy an object:
If a class has already a non trivial constructor or destructor, for example when it has to manage dynamic resources or it implements some scoped behaviour, like for example a scoped_lock.
| classname | The name of the class |
| #define FCPPT_SAFE_BOOL | ( | classname | ) |
Implements the safe bool idiom for a class.
Implements the safe bool idiom for a class called classname. The macro must be placed inside the class definition and called with the name of the class.
It generates a member function that makes it possible to use objects of this class as a condition like in if(object). However, objects of this class are not convertible to bool or any other integral types.
To tell when the expression object should evaluate to true, the member function bool boolean_test() const must be implemented.
In the following example, a class is defined using the safe bool idiom:
An object of this class can then be used in an if statement:
| classname | The name of the class |
| #define FCPPT_STATIC_ASSERT_EXPRESSION | ( | cond | ) |
Assert at compile time that a condition is true, using an expression.
This macro asserts at compile that cond is true, using an expression. It is therefore preferred to use this macro to assert a condition in a function. It will not generate any typedefs that might lead to warnings.
| #define FCPPT_STATIC_ASSERT_STATEMENT | ( | cond | ) |
Assert at compile time that a condition is true, using a statement.
This macro asserts at compile that cond is true, using a statement. It must be used whenever an expression is not allowed.
|
inline |
Partial replacement for C++11's nullptr.
This function is a partial replacement for C++11's nullptr. It can be used for pointers to objects and pointers to functions only. Member function pointers are currently not supported.
The reason for this function's existance is that the literal 0 or the macro NULL can be misused in C++ because they are convertible to a lot of other things. Here is an example:
1.8.2