1 #ifndef SIPLASPLAS_TYPEERASURE_TYPEINFO_HPP 2 #define SIPLASPLAS_TYPEERASURE_TYPEINFO_HPP 4 #include "features/valuesemantics.hpp" 5 #include <siplasplas/utility/memory_manip.hpp> 6 #include <siplasplas/utility/meta.hpp> 7 #include <siplasplas/utility/function_traits.hpp> 31 using ValueSemanticsOperationFunction = void(*)(
void*,
const void*);
57 static ValueSemanticsOperationFunction operations[] = {
58 +[](
void* object,
const void* other) {
59 features::CopyConstructible::apply<T>(object, other);
61 +[](
void* object,
const void* other) {
62 features::MoveConstructible::apply<T>(object,
const_cast<void*
>(other));
64 +[](
void* object,
const void* other) {
65 features::CopyAssignable::apply<T>(object, other);
67 +[](
void* object,
const void* other) {
68 features::MoveAssignable::apply<T>(object,
const_cast<void*
>(other));
70 +[](
void* object,
const void*) {
71 features::Destructible::apply<T>(object);
75 return operations[
static_cast<std::size_t
>(operation)];
78 using ValueSemantics = decltype(&valueSemanticsOperation<int>);
116 #if UINTPTR_MAX == UINT64_MAX // See constructor bellow 136 return _typeId.name().c_str();
153 return semantics()(operation);
165 semantics(detail::ValueSemanticsOperation::COPY_CONSTRUCT)(where, other);
178 semantics(detail::ValueSemanticsOperation::MOVE_CONSTRUCT)(where,
const_cast<const void*
>(other));
190 semantics(detail::ValueSemanticsOperation::COPY_ASSIGN)(where, other);
203 semantics(detail::ValueSemanticsOperation::MOVE_ASSIGN)(where,
const_cast<const void*
>(other));
216 semantics(detail::ValueSemanticsOperation::DESTROY)(where,
nullptr);
226 return TypeInfo{meta::identity<T>()};
231 return lhs._semantics == rhs._semantics;
236 return !(lhs == rhs);
241 constexpr
TypeInfo(meta::identity<T>) :
244 #if UINTPTR_MAX == UINT64_MAX 247 _typeId{ctti::type_id<T>()},
249 std::is_pointer<T>::value &&
250 cpp::function_kind<T>() != cpp::FunctionKind::FREE_FUNCTION
253 static_assert(
alignof(T) < (1 << 16),
"Alignment of T cannot be tagged in a pointer, its value overflows a 16 bit unsigned integer");
267 _semantics{&valueSemanticsOperation<T>},
268 _alignment{
alignof(T)},
270 _typeId{ctti::type_id<T>()},
272 std::is_pointer<T>::value &&
273 cpp::function_kind<T>() != cpp::FunctionKind::FREE_FUNCTION
281 constexpr std::size_t alignment()
const 287 std::size_t _alignment;
288 #endif // if not 64 bit 289 detail::ValueSemantics _semantics;
291 ctti::type_id_t _typeId;
299 #endif // SIPLASPLAS_TYPEERASURE_TYPEINFO_HPP ValueSemanticsOperation
Represents a value semantics operation. See valueSemanticsOperation()
Definition: typeinfo.hpp:22
T * untagPointer(T *pointer)
Untags a pointer.
Definition: memory_manip.hpp:220
void moveConstruct(void *where, void *other) const
Move constructs values of the type If the passed arguments are not of the represented type...
Definition: typeinfo.hpp:176
Definition: canary_allocator.hpp:7
detail::ValueSemanticsOperationFunction semantics(detail::ValueSemanticsOperation operation) const
Returns the function implementing the given valuesemantics operation for the type.
Definition: typeinfo.hpp:151
ValueSemanticsOperationFunction valueSemanticsOperation(ValueSemanticsOperation operation)
Implements a type-erased interface for the value semantics features of a type T.
Definition: typeinfo.hpp:55
detail::ValueSemantics semantics() const
Retuns the type-erased semantics of the type. See valueSemantics().
Definition: typeinfo.hpp:114
std::size_t alignment() const
returns the alignment of the type
Definition: typeinfo.hpp:260
void copyConstruct(void *where, const void *other) const
Copy constructs values of the type If the passed arguments are not of the represented type...
Definition: typeinfo.hpp:163
void destroy(void *where) const
Destroys objects of the type If the passed arguments are not of the represented type, the behavior is undefined.
Definition: typeinfo.hpp:212
void copyAssign(void *where, const void *other) const
Move assigns values of the type If the passed arguments are not of the represented type...
Definition: typeinfo.hpp:188
bool isPointer() const
Checks if the type is a pointer type.
Definition: typeinfo.hpp:142
std::uint16_t readTaggedPointer(T *pointer)
Reads the data stored in a tagged pointer.
Definition: memory_manip.hpp:260
const char * typeName() const
Returns the name of the type.
Definition: typeinfo.hpp:134
void moveAssign(void *where, void *other) const
Move assigns values of the type If the passed arguments are not of the represented type...
Definition: typeinfo.hpp:201
Contains minimal information to execute the value semantics operations of a type. ...
Definition: typeinfo.hpp:108
T * tagPointer(T *pointer, U data)
Tags a pointer with the specified data.
Definition: memory_manip.hpp:177
std::size_t sizeOf() const
Returns the size of the type.
Definition: typeinfo.hpp:126