siplasplas
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
cpp::typeerasure::TypeInfo Class Reference

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

#include <typeinfo.hpp>

Inheritance diagram for cpp::typeerasure::TypeInfo:
cpp::TypeInfo

Public Member Functions

detail::ValueSemantics semantics () const
 Retuns the type-erased semantics of the type. More...
 
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 defaultConstruct (void *where) const
 Default constructs a value of the type If the passed argument is not of the represented type, the behavior is undefined. More...
 
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...
 
constexpr cpp::constexp::ConstArrayView< TypeInfoarguments () const
 Returns the type information of the function arguments. More...
 
- Public Member Functions inherited from cpp::TypeInfo
constexpr bool operator() (const TypeTraitIndex typeTrait) const
 
constexpr ctti::detail::cstring name () const
 
constexpr ctti::detail::cstring typeName () const
 
constexpr const ctti::type_id_t & type_id () const
 
constexpr std::size_t sizeOf () const
 
constexpr std::size_t alignment () const
 
constexpr cpp::FunctionKind kind () const
 
constexpr bool isPointer () const
 

Static Public Member Functions

template<typename T >
static constexpr TypeInfo get ()
 Returns the type information of type T.
 
template<typename T >
static constexpr TypeInfo get (const T &)
 Returns the type information of type T.
 
- Static Public Member Functions inherited from cpp::TypeInfo
template<typename T >
static constexpr TypeInfo get ()
 

Friends

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

Additional Inherited Members

- Public Types inherited from cpp::TypeInfo
enum  TypeTraitIndex : std::size_t {
  is_void, is_null_pointer, is_integral, is_floating_point,
  is_array, is_enum, is_union, is_class,
  is_function, is_pointer, is_lvalue_reference, is_rvalue_reference,
  is_member_object_pointer, is_member_function_pointer, is_fundamental, is_arithmetic,
  is_scalar, is_object, is_compound, is_reference,
  is_member_pointer, is_const, is_volatile, is_trivial,
  is_trivially_copyable, is_standard_layout, is_pod, is_literal_type,
  is_empty, is_polymorphic, is_abstract, is_signed,
  is_unsigned, is_default_constructible, is_copy_constructible, is_move_constructible,
  is_copy_assignable, is_move_assignable, is_destructible, is_trivially_default_constructible,
  is_trivially_copy_constructible, is_trivially_move_constructible, is_trivially_copy_assignable, is_trivially_move_assignable,
  is_trivially_destructible, is_nothrow_default_constructible, is_nothrow_copy_constructible, is_nothrow_move_constructible,
  is_nothrow_copy_assignable, is_nothrow_move_assignable, is_nothrow_destructible, has_virtual_destructor,
  ALWAYS_AT_END_PLEASE__ACTUALLY_NOT_A_TRAIT_INDEX
}
 
using BitsetValue = std::uint64_t
 
using TypeTraits = std::bitset< static_cast< std::size_t >(TypeTraitIndex::ALWAYS_AT_END_PLEASE__ACTUALLY_NOT_A_TRAIT_INDEX)>
 

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

§ arguments()

constexpr cpp::constexp::ConstArrayView<TypeInfo> cpp::typeerasure::TypeInfo::arguments ( ) const
inline

Returns the type information of the function arguments.

The behavior is undefined if the type is not a function type

§ copyAssign()

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

§ copyConstruct()

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

§ defaultConstruct()

void cpp::typeerasure::TypeInfo::defaultConstruct ( void *  where) const
inline

Default constructs a value of the type If the passed argument is not of the represented type, the behavior is undefined.

Parameters
whereAddress of the object to be constructed

§ destroy()

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

§ moveAssign()

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).

§ moveConstruct()

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).

§ semantics()

detail::ValueSemantics cpp::typeerasure::TypeInfo::semantics ( ) const
inline

Retuns the type-erased semantics of the type.

See valueSemantics().


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