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> 8 #include <siplasplas/utility/typeinfo.hpp> 25 DEFAULT_CONSTRUCT = 0,
33 using ValueSemanticsOperationFunction = void(*)(
void*,
const void*);
59 static ValueSemanticsOperationFunction operations[] = {
60 +[](
void* object,
const void*) {
61 features::DefaultConstructible::apply<T>(object);
63 +[](
void* object,
const void* other) {
64 features::CopyConstructible::apply<T>(object, other);
66 +[](
void* object,
const void* other) {
67 features::MoveConstructible::apply<T>(object,
const_cast<void*
>(other));
69 +[](
void* object,
const void* other) {
70 features::CopyAssignable::apply<T>(object, other);
72 +[](
void* object,
const void* other) {
73 features::MoveAssignable::apply<T>(object,
const_cast<void*
>(other));
75 +[](
void* object,
const void*) {
76 features::Destructible::apply<T>(object);
80 return operations[
static_cast<std::size_t
>(operation)];
83 using ValueSemantics = decltype(&valueSemanticsOperation<int>);
138 return semantics()(operation);
149 semantics(detail::ValueSemanticsOperation::DEFAULT_CONSTRUCT)(where,
nullptr);
161 semantics(detail::ValueSemanticsOperation::COPY_CONSTRUCT)(where, other);
174 semantics(detail::ValueSemanticsOperation::MOVE_CONSTRUCT)(where,
const_cast<const void*
>(other));
186 semantics(detail::ValueSemanticsOperation::COPY_ASSIGN)(where, other);
199 semantics(detail::ValueSemanticsOperation::MOVE_ASSIGN)(where,
const_cast<const void*
>(other));
212 semantics(detail::ValueSemanticsOperation::DESTROY)(where,
nullptr);
222 return TypeInfo{meta::identity<T>()};
227 return lhs._semantics == rhs._semantics;
232 return !(lhs == rhs);
237 constexpr
TypeInfo(meta::identity<T>) :
238 cpp::TypeInfo{cpp::TypeInfo::get<T>()},
239 _semantics{detail::valueSemanticsOperation<T>},
241 std::is_pointer<T>::value &&
242 cpp::function_kind<T>() != cpp::FunctionKind::FREE_FUNCTION
245 static_assert(
alignof(T) < (1 << 16),
"Alignment of T cannot be tagged in a pointer, its value overflows a 16 bit unsigned integer");
248 detail::ValueSemantics _semantics;
256 #endif // SIPLASPLAS_TYPEERASURE_TYPEINFO_HPP ValueSemanticsOperation
Represents a value semantics operation. See valueSemanticsOperation()
Definition: typeinfo.hpp:23
void defaultConstruct(void *where) const
Default constructs a value of the type If the passed argument is not of the represented type...
Definition: typeinfo.hpp:147
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:172
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:136
ValueSemanticsOperationFunction valueSemanticsOperation(ValueSemanticsOperation operation)
Implements a type-erased interface for the value semantics features of a type T.
Definition: typeinfo.hpp:57
detail::ValueSemantics semantics() const
Retuns the type-erased semantics of the type. See valueSemantics().
Definition: typeinfo.hpp:119
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:159
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:208
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:184
bool isPointer() const
Checks if the type is a pointer type.
Definition: typeinfo.hpp:127
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:197
Contains minimal information to execute the value semantics operations of a type. ...
Definition: typeinfo.hpp:113