siplasplas
A library for C++ reflection and introspection
|
Some random utilities needed by other siplasplas modules. More...
Modules | |
Assert | |
Assertion utilities. | |
Dynamic-library | |
Cross platform API to load symbols from shared librarties at runtime. | |
Error-handling | |
Error handling tools. | |
Hash | |
Hashing utilities based on std::hash . | |
Memory-manip | |
Tools related to raw memory manipulation. | |
Classes | |
class | cpp::Identity |
A functor class implementing the identity function. More... | |
class | cpp::UniversalReference< T, IsLvalueReference, IsConst > |
Implements a copyable wrapper of an universal reference. More... | |
class | cpp::UniversalReference< T, true, false > |
UniversalReference spacialization for non-const lvalues. More... | |
class | cpp::UniversalReference< T, false, false > |
UniversalReference spacialization for rvalues. More... | |
Functions | |
template<typename T > | |
void | cpp::destroy (T &object) |
Invokes the destructor of an object. More... | |
template<typename T > | |
void | cpp::destroy (T *objectPtr) |
Invokes the destructor of an object. More... | |
template<typename T , typename... Args> | |
void | cpp::construct (void *where, Args &&...args) |
constructs an object of type T on the specified address More... | |
template<typename T , typename... Args> | |
void | cpp::construct (T *where, Args &&...args) |
constructs an object of type T on the specified address More... | |
template<typename Callable , typename... Args> | |
decltype(auto) | cpp::invoke (Callable &&callable, Args &&...args) |
Invokes the Callable object with the given arguments. See std::invoke() | |
template<typename T > | |
std::string | cpp::lexical_cast (const T &value) |
Returns an string representation of a value. More... | |
template<typename T > | |
T | cpp::lexical_cast (const std::string &value) |
Returns an string representation of a value. More... | |
template<bool Condition, typename ThenBody , typename... Args> | |
auto | cpp::staticIf (const ThenBody &thenBody, Args &&...args) |
Implements an static conditional. More... | |
template<typename T > | |
auto | cpp::universalReference (T &&value) -> UniversalReference< std::decay_t< T >, std::is_lvalue_reference< T >::value, std::is_const< std::remove_reference_t< T >>::value > |
Creates an universal reference to the given value. More... | |
Some random utilities needed by other siplasplas modules.
The siplaspals-utility module implements various utilities used in the implementation of other siplasplas modules. These utilities are not grouped in any special way, but we encourage the policy of rising utilities into full-fledged modules if these became too complex.
Move meta.hpp, function_traits.hpp, tuple.hpp, and fusion.hpp to a siplasplas-meta module.
Move error_logger.hpp and exception.hpp to a siplasplas-exception module?
Move cpp::Overload<> to function_traits.hpp
siplasplas-utility includes the following features:
void cpp::construct | ( | void * | where, |
Args &&... | args | ||
) |
constructs an object of type T on the specified address
This function performs an in-place construction of an object of type T in the given address. Arguments are passed as-is to the object constructor. The behavior is undefined if alignment(pointer) != alignof(T)
.
where | Location of the object |
args | Constructor arguments |
void cpp::construct | ( | T * | where, |
Args &&... | args | ||
) |
constructs an object of type T on the specified address
This function performs an in-place construction of an object of type T in the given address. Arguments are passed as-is to the object constructor. The behavior is undefined if alignment(pointer) != alignof(T)
.
where | Location of the object |
args | Constructor arguments |
void cpp::destroy | ( | T & | object | ) |
Invokes the destructor of an object.
T | Must be Destructible (See std::is_destructible) |
void cpp::destroy | ( | T * | objectPtr | ) |
Invokes the destructor of an object.
T | Must be Destructible (See std::is_destructible) |
std::string cpp::lexical_cast | ( | const T & | value | ) |
Returns an string representation of a value.
This function invokes operator<<(std::ostream&, const T&)
to get an string representation of a given value.
It's a simplified version of the Boost.Lexical_Cast library.
T | value type. Must have a valid operator<<(std::ostream&, T) overload. |
value | Value which is translated to a string. |
T cpp::lexical_cast | ( | const std::string & | value | ) |
Returns an string representation of a value.
This function invokes operator>>(std::istream&, T&)
to assign a T value from an string representation of it.
It's a simplified version of the Boost.Lexical_Cast library.
T | Required output value type. Must have a valid operator>>(std::istream&, T&) overload. |
value | String representation of the value. |
T
equivalent to the value
string representation argument. auto cpp::staticIf | ( | const ThenBody & | thenBody, |
Args &&... | args | ||
) |
Implements an static conditional.
An static conditional allows to conditionally evaluate some code depending on the value of a compile time property. The body of the conditional is implemented by user provided functions.
The body of the untaken conditional path shall not be evaluated by the compiler and can contain ill formed code. NOTE: This behavior relies on the two phase template processing scheme, so the statement above is only true for entities that will be evaluated in the instantiation phase only:
As the example shows, the conditional body takes an identity
parameter that can be used to force the evaluation of an expression at the second phase.
The static conditional expression also provides an else
sentence in the form of an Else()
method:
cpp::staticIf() supports returning values from the conditional body too:
note this has some caveats:
auto
or any other kind of type inference cannot be used with the return value of a static conditional.then
path is picked. If the then
body returns a value, such value is not returned directly (So elligible for RVO) but bypassed through the else
internals. This means returning a value from a positive conditional may involve two move operations.Condition | Value of the condition. The value should be evaluable at compile time, else compilation fails. |
ThenBody | Function type with one template-dependent value parameter. |
thenBody | Body of the then path of the conditional. Evaluated only if the condition is true. |
else
part of the conditional. auto cpp::universalReference | ( | T && | value | ) | -> UniversalReference< std::decay_t<T>, std::is_lvalue_reference<T>::value, std::is_const<std::remove_reference_t<T>>::value > |
Creates an universal reference to the given value.
This function checks the value category of the given value and instances the apropiate cpp::UniversalReference specialization. Note the returned type depends on the value category. For an alternative with common a type, see cpp::typeerasure::AnyArg
UniversalReference<std::decay_t<T>, true, true>
if value
type is deduced to a const reference to an lvalue.UniversalReference<std::decay_t<T>, true, false>
if value
type is deduced to a non const reference to an lvalue.UniversalReference<std::decay_t<T>, false, false>
if value
type is deduced to an rvalue reference