siplasplas
A library for C++ reflection and introspection
cpp::typeerasure::TypeInfo Class Reference

Contains minimal information to execute the value semantics operations of a type. More...

#include <siplasplas/typeerasure/typeinfo.hpp>

Public Member Functions

detail::ValueSemantics semantics () const
 Retuns the type-erased semantics of the type. See valueSemantics().
 
std::size_t sizeOf () const
 Returns the size of the type.
 
const char * typeName () const
 Returns the name of the type.
 
bool isPointer () const
 Checks if the type is a pointer type.
 
detail::ValueSemanticsOperationFunction semantics (detail::ValueSemanticsOperation operation) const
 Returns the function implementing the given valuesemantics operation for the type.
 
void copyConstruct (void *where, const void *other) const
 Copy constructs values of the type If the passed arguments are not of the represented type, the behavior is undefined. More...
 
void moveConstruct (void *where, void *other) const
 Move constructs values of the type If the passed arguments are not of the represented type, the behavior is undefined. More...
 
void copyAssign (void *where, const void *other) const
 Move assigns values of the type If the passed arguments are not of the represented type, the behavior is undefined. More...
 
void moveAssign (void *where, void *other) const
 Move assigns values of the type If the passed arguments are not of the represented type, the behavior is undefined. More...
 
void destroy (void *where) const
 Destroys objects of the type If the passed arguments are not of the represented type, the behavior is undefined. More...
 
std::size_t alignment () const
 returns the alignment of the type
 

Static Public Member Functions

template<typename T >
static constexpr TypeInfo get ()
 Returns the type information of type T.
 

Friends

constexpr bool operator== (const TypeInfo &lhs, const TypeInfo &rhs)
 
constexpr bool operator!= (const TypeInfo &lhs, const TypeInfo &rhs)
 

Detailed Description

Contains minimal information to execute the value semantics operations of a type.

This class stores the alignment and value semantics operations of a type. The value semantics operations are aset of type-erased functions mapping to the different value semantics features (CopyConstructible, DefaultConstructible, etc). This mapping is implemented as a lookup table of function pointers.

std::aligned_storage<sizeof(std::string), alignof(std::string)> stringStorage;
std::string str = "hello, world!";
auto typeInfo = TypeInfo::get<std::string>();
// Copy construct the string from str:
typeInfo.copyConstruct(&stringStorage, &str);
// Or if there's no access to a properly aligned storage, use TypeInfo::alignment():
char buffer[64];
typeInfo.copyConstruct(
cpp::detail::aligned_ptr(&buffer[0], typeInfo.alignment()), // Get an aligned address first
&str
);

Member Function Documentation

void cpp::typeerasure::TypeInfo::copyAssign ( void *  where,
const void *  other 
) const
inline

Move assigns values of the type If the passed arguments are not of the represented type, the behavior is undefined.

Parameters
whereAddress of the object to be assigned to
otherAddress of the object to assign from
void cpp::typeerasure::TypeInfo::copyConstruct ( void *  where,
const void *  other 
) const
inline

Copy constructs values of the type If the passed arguments are not of the represented type, the behavior is undefined.

Parameters
whereAddress of the object to be constructed
otherAddress of the object to copy from
void cpp::typeerasure::TypeInfo::destroy ( void *  where) const
inline

Destroys objects of the type If the passed arguments are not of the represented type, the behavior is undefined.

Parameters
wherePointer to the object to destroy
void cpp::typeerasure::TypeInfo::moveAssign ( void *  where,
void *  other 
) const
inline

Move assigns values of the type If the passed arguments are not of the represented type, the behavior is undefined.

Parameters
whereAddress of the object to be assigned to
otherReference of the object to assign from (The pointer is a pointer to the rvalue reference up in the call stack).
void cpp::typeerasure::TypeInfo::moveConstruct ( void *  where,
void *  other 
) const
inline

Move constructs values of the type If the passed arguments are not of the represented type, the behavior is undefined.

Parameters
whereAddress of the object to be constructed
otherReference of the object to move from (The pointer is a pointer to the rvalue reference up in the call stack).

The documentation for this class was generated from the following file: