C++ utility and idioms, such as noncopyable base classes, foreach macros or safe bool idiom. More...
Classes | |
class | aurora::Any |
Type-erased class holding any value. More... | |
class | aurora::Exception |
Exception base class. More... | |
class | aurora::FunctionCallException |
Exception class for failed function calls. More... | |
struct | aurora::PairHasher |
Hash object for std::pair. More... | |
class | aurora::NonCopyable |
Non-copyable base class. More... | |
struct | aurora::NulloptType |
Null literal for optional objects. More... | |
struct | aurora::InplaceType |
Tag to construct optional objects in-place. More... | |
class | aurora::Optional< T > |
Represents optional values. More... | |
class | aurora::PImpl< T, Size, Align > |
Fast PImpl idiom. More... | |
Macros | |
#define | AURORA_FOREACH(declaration, container) |
Macro that emulates C++11 range-based for loop. More... | |
#define | AURORA_NT_EQUAL(TupleName, typeVarPairs) |
Comparison operator == for named tuples. More... | |
#define | AURORA_NT_LESS(TupleName, typeVarPairs) |
Comparison operator < for named tuples. More... | |
#define | AURORA_NT_HASHER(TupleName, typeVarPairs) |
Hash functor for named tuples. More... | |
#define | AURORA_NT_DEFAULT_CTOR(TupleName, typeVarPairs) |
Default constructor for named tuples. More... | |
#define | AURORA_NAMED_TUPLE(TupleName, typeVarPairs) |
Named tuple definition. More... | |
#define | AURORA_NAMED_TUPLE_EXT(TupleName, typeVarPairs, extensions) |
Named tuple definition with extended functionality. More... | |
#define | AURORA_GLOBAL_SWAP(Class) |
Macro to implement a global overload of swap(lhs, rhs) to allow argument-dependent lookup. More... | |
Typedefs | |
typedef void(detail::SafeBoolHolder::* | aurora::SafeBool) () |
SafeBool type. | |
Functions | |
template<typename T > | |
bool | aurora::equivalent (const T &lhs, const T &rhs) |
Determines whether two values are considered equivalent in sorting. More... | |
template<typename ForwardIterator , typename T > | |
ForwardIterator | aurora::binarySearch (ForwardIterator first, ForwardIterator last, const T &value) |
Binary search for value in iterator range. More... | |
template<typename Container , typename Iterator > | |
void | aurora::eraseUnordered (Container &c, Iterator itr) |
Erase element using swap-and-pop_back idiom. More... | |
template<typename Container , typename Value > | |
void | aurora::remove (Container &c, const Value &v) |
Erase-remove idiom. More... | |
template<typename Container , typename Predicate > | |
void | aurora::removeIf (Container &c, const Predicate &p) |
Erase-remove-if idiom. More... | |
template<typename Queue > | |
Queue::value_type | aurora::pop (Queue &q) |
Pop from queue with return value. More... | |
template<typename Queue > | |
void | aurora::clearQueue (Queue &q) |
Clear std::queue. More... | |
template<typename AssocContainer , typename Key > | |
AssocContainer::mapped_type & | aurora::mapAt (AssocContainer &map, const Key &k) |
Returns the value type for a specific key. More... | |
template<typename To , typename From > | |
To | aurora::downcast (From &base) |
Safe polymorphic downcast for references. More... | |
template<typename To , typename From > | |
To | aurora::downcast (From *base) |
Safe polymorphic downcast for pointers. More... | |
template<typename T > | |
std::size_t | aurora::hashValue (const T &object) |
Computes the hash value of an object (short-hand notation). | |
template<typename T > | |
void | aurora::hashCombine (std::size_t &seed, const T &object) |
Combines a hash with the hash value of another object. | |
template<typename Itr > | |
void | aurora::hashRange (std::size_t &seed, Itr begin, Itr end) |
Combines a hash with the hash value of a range of objects. | |
SafeBool | aurora::toSafeBool (bool condition) |
Conversion function from bool to SafeBool. | |
template<typename T > | |
void | adlSwap (T &lhs, T &rhs) |
swap() function with argument-dependent lookup More... | |
template<typename T > | |
std::type_index | aurora::typeIndex (T &reference) |
Safe typeid operator for references. More... | |
template<typename T > | |
std::type_index | aurora::typeIndex () |
Safe typeid operator for types. More... | |
template<typename T > | |
void | swap (Optional< T > &lhs, Optional< T > &rhs) |
Swaps two optionals. | |
template<typename T , typename... Args> | |
Optional< T > | makeOptional (Args &&...args) |
Emplaces an object directly inside the aurora::Optional object. More... | |
template<typename T > | |
bool | operator== (const Optional< T > &lhs, const Optional< T > &rhs) |
Equality comparison. More... | |
template<typename T > | |
bool | operator!= (const Optional< T > &lhs, const Optional< T > &rhs) |
Inequality comparison. More... | |
template<typename T , std::size_t Size, std::size_t Align> | |
void | swap (PImpl< T, Size, Align > &lhs, PImpl< T, Size, Align > &rhs) |
Swaps two implementation objects. | |
Variables | |
const SafeBool | aurora::SafeBoolTrue |
SafeBool literal, evaluates to true. | |
const SafeBool | aurora::SafeBoolFalse |
SafeBool literal, evaluates to false. | |
C++ utility and idioms, such as noncopyable base classes, foreach macros or safe bool idiom.
#define AURORA_FOREACH | ( | declaration, | |
container | |||
) |
#define AURORA_GLOBAL_SWAP | ( | Class | ) |
Macro to implement a global overload of swap(lhs, rhs)
to allow argument-dependent lookup.
Accesses the member function void Class::swap(Class&)
.
#define AURORA_NAMED_TUPLE | ( | TupleName, | |
typeVarPairs | |||
) |
Named tuple definition.
Defines a struct type with a specified list of public members and a corresponding constructor.
TupleName | Name of the struct |
typeVarPairs | Parenthesized sequence of (Type, variable) pairs, such as ((int, i), (double, d)) |
Example:
#define AURORA_NAMED_TUPLE_EXT | ( | TupleName, | |
typeVarPairs, | |||
extensions | |||
) |
Named tuple definition with extended functionality.
Defines a struct type with a specified list of public members and a corresponding constructor.
TupleName | Name of the struct |
typeVarPairs | Parenthesized sequence of (Type, variable) pairs, such as ((int, i), (double, d)) |
extensions | Parenthesized sequence of extensions, such as (AURORA_NT_EQUAL, AURORA_NT_LESS). Possible arguments are all macros that begin with AURORA_NT_. |
Example:
#define AURORA_NT_DEFAULT_CTOR | ( | TupleName, | |
typeVarPairs | |||
) |
Default constructor for named tuples.
Supplies the named tuple with a default constructor calls each members' default constructor. Do not invoke this macro directly. It is passed to AURORA_NAMED_TUPLE_EXT.
#define AURORA_NT_EQUAL | ( | TupleName, | |
typeVarPairs | |||
) |
Comparison operator == for named tuples.
Supplies the named tuple with an operator== in the surrounding namespace, which compares member-wise. Do not invoke this macro directly. It is passed to AURORA_NAMED_TUPLE_EXT.
#define AURORA_NT_HASHER | ( | TupleName, | |
typeVarPairs | |||
) |
Hash functor for named tuples.
Supplies the named tuple with a member typedef Hasher
inside the tuple class. Do not invoke this macro directly. It is passed to AURORA_NAMED_TUPLE_EXT.
#define AURORA_NT_LESS | ( | TupleName, | |
typeVarPairs | |||
) |
Comparison operator < for named tuples.
Supplies the named tuple with an operator< in the surrounding namespace, which compares lexicographically. Do not invoke this macro directly. It is passed to AURORA_NAMED_TUPLE_EXT.
void adlSwap | ( | T & | lhs, |
T & | rhs | ||
) |
swap() function with argument-dependent lookup
Chooses the best overload of swap(lhs, rhs)
with argument-dependent lookup. If none is found, std::swap()
will be called.
ForwardIterator aurora::binarySearch | ( | ForwardIterator | first, |
ForwardIterator | last, | ||
const T & | value | ||
) |
Binary search for value in iterator range.
Performs a binary search with a useful return value, in contrast to std::binary_search().
first,last | Iterator range |
value | Value to search for |
void aurora::clearQueue | ( | Queue & | q | ) |
Clear std::queue.
Calls pop() repeatedly until the queue is empty.
To aurora::downcast | ( | From & | base | ) |
Safe polymorphic downcast for references.
Can be used in place of a static_cast from a base class to a derived class – that is, you expect the downcast to succeed. In debug mode, types are checked at runtime using dynamic_cast. In release mode (with the NDBEBUG macro defined), a static_cast at full speed is used.
To aurora::downcast | ( | From * | base | ) |
Safe polymorphic downcast for pointers.
Can be used in place of a static_cast from a base class to a derived class – that is, you expect the downcast to succeed. In debug mode, types are checked at runtime using dynamic_cast. In release mode (with the NDBEBUG macro defined), a static_cast at full speed is used.
bool aurora::equivalent | ( | const T & | lhs, |
const T & | rhs | ||
) |
Determines whether two values are considered equivalent in sorting.
Equal implies equivalent, but not vice versa. Two values are considered equivalent if neither appears before the other (w.r.t. sorting criterion, here operator<)
void aurora::eraseUnordered | ( | Container & | c, |
Iterator | itr | ||
) |
Erase element using swap-and-pop_back idiom.
Erases the element at position itr
by swapping it with the last element in the container and erasing the last element. This O(1) operation is particularly useful for std::vector or std::deque as long as the element order is not relevant.
|
related |
Emplaces an object directly inside the aurora::Optional object.
Example:
args | Variable argument list, the single arguments are forwarded to T's constructor. |
AssocContainer::mapped_type& aurora::mapAt | ( | AssocContainer & | map, |
const Key & | k | ||
) |
Returns the value type for a specific key.
Assumes existence of the key, returns corresponding mapped type without inserting it. In contrast to std::[unordered_]map::at()
, this does not throw exceptions. If the key is not available, the behavior is undefined, in favor of optimized performance.
|
related |
Inequality comparison.
|
related |
Equality comparison.
Semantics: Returns true if both operands are empty, or if both are non-empty and the expression *lhs == *rhs
returns true.
Queue::value_type aurora::pop | ( | Queue & | q | ) |
Pop from queue with return value.
Combines std::queue's pop() and front() operations.
void aurora::remove | ( | Container & | c, |
const Value & | v | ||
) |
Erase-remove idiom.
Removes value v
from sequential container c
(std::vector or std::deque)
void aurora::removeIf | ( | Container & | c, |
const Predicate & | p | ||
) |
Erase-remove-if idiom.
Removes value v
from sequential container c
(std::vector or std::deque)
std::type_index aurora::typeIndex | ( | T & | reference | ) |
Safe typeid operator for references.
The C++ typeid operator can easily be used incorrectly in RTTI scenarios, leading to tedious bugs at runtime:
This implementation makes sure that the above-mentioned cases do not occur. Type verification happens at compile time, so there is no performance overhead in using this function. This function is specifically designed for the use of RTTI in polymorphic class hierarchies, it cannot be used in other scenarios (e.g. printing arbitrary type names for debugging).
Usage:
std::type_index aurora::typeIndex | ( | ) |
Safe typeid operator for types.
Same as typeIndex(T& reference)
, but for types.
Usage: