alpaqa 1.0.0a15
Nonconvex constrained optimization
Loading...
Searching...
No Matches
type-erasure.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
7
8#include <algorithm>
9#include <cassert>
10#include <cstddef>
11#include <functional>
12#include <memory>
13#include <new>
14#include <stdexcept>
15#include <type_traits>
16#include <typeinfo>
17#include <utility>
18
19namespace alpaqa::util {
20
21class ALPAQA_EXPORT bad_type_erased_type : public std::logic_error {
22 public:
23 bad_type_erased_type(const std::type_info &actual_type,
24 const std::type_info &requested_type,
25 const std::string &message = "")
26 : std::logic_error{message}, actual_type{actual_type},
27 requested_type{requested_type} {}
28
29 [[nodiscard]] const char *what() const noexcept override {
30 message = "";
31 if (const char *w = std::logic_error::what(); w && *w) {
32 message += w;
33 message += ": ";
34 }
35 message = "Type requested: " + demangled_typename(requested_type) +
36 ", type contained: " + demangled_typename(actual_type);
37 return message.c_str();
38 }
39
40 private:
41 const std::type_info &actual_type;
42 const std::type_info &requested_type;
43 mutable std::string message;
44};
45
46class ALPAQA_EXPORT bad_type_erased_constness : public std::logic_error {
47 public:
49 : std::logic_error{"Non-const method called on a TypeErased object "
50 "that references a const object"} {}
51};
52
53/// Struct that stores the size of a polymorphic object, as well as pointers to
54/// functions to copy, move or destroy the object.
55/// Inherit from this struct to add useful functions.
57
58 template <class>
59 struct required_function; // undefined
60 template <class R, class... Args>
61 struct required_function<R(Args...)> {
62 using type = R (*)(void *self, Args...);
63 };
64 template <class R, class... Args>
66 using type = R (*)(const void *self, Args...);
67 };
68 template <class, class VTable = BasicVTable>
69 struct optional_function; // undefined
70 template <class R, class... Args, class VTable>
71 struct optional_function<R(Args...), VTable> {
72 using type = R (*)(void *self, Args..., const VTable &);
73 };
74 template <class R, class... Args, class VTable>
75 struct optional_function<R(Args...) const, VTable> {
76 using type = R (*)(const void *self, Args..., const VTable &);
77 };
78 /// A required function includes a void pointer to self, in addition to the
79 /// arguments of @p F.
80 template <class F>
82 /// An optional function includes a void pointer to self, the arguments of
83 /// @p F, and an additional reference to the VTable, so that it can be
84 /// implemented in terms of other functions.
85 template <class F, class VTable = BasicVTable>
87
88 /// Copy-construct a new instance into storage.
89 required_function_t<void(void *storage) const> copy = nullptr;
90 /// Move-construct a new instance into storage.
91 required_function_t<void(void *storage)> move = nullptr;
92 /// Destruct the given instance.
94 /// The original type of the stored object.
95 const std::type_info *type = &typeid(void);
96
97 BasicVTable() = default;
98
99 template <class T>
100 BasicVTable(std::in_place_t, T &) noexcept {
101 copy = [](const void *self, void *storage) {
102 new (storage) T(*std::launder(reinterpret_cast<const T *>(self)));
103 };
104 // TODO: require that move constructor is noexcept?
105 move = [](void *self, void *storage) noexcept {
106 new (storage)
107 T(std::move(*std::launder(reinterpret_cast<T *>(self))));
108 };
109 destroy = [](void *self) {
110 std::launder(reinterpret_cast<T *>(self))->~T();
111 };
112 type = &typeid(T);
113 }
114};
115
116namespace detail {
117template <class Class, class... ExtraArgs>
118struct Launderer {
119 private:
120 template <auto M, class V, class C, class R, class... Args>
121 [[gnu::always_inline]] static constexpr auto
122 do_invoke(V *self, Args... args, ExtraArgs...) -> R {
123 return std::invoke(M, *std::launder(reinterpret_cast<C *>(self)),
124 std::forward<Args>(args)...);
125 }
126 template <auto M, class T, class R, class... Args>
127 requires std::is_base_of_v<T, Class>
128 [[gnu::always_inline]] static constexpr auto invoker_ovl(R (T::*)(Args...)
129 const) {
130 return do_invoke<M, const void, const Class, R, Args...>;
131 }
132 template <auto M, class T, class R, class... Args>
133 requires std::is_base_of_v<T, Class>
134 [[gnu::always_inline]] static constexpr auto
135 invoker_ovl(R (T::*)(Args...)) {
136 if constexpr (std::is_const_v<Class>)
137 return +[](void *, Args..., ExtraArgs...) {
139 };
140 else
141 return do_invoke<M, void, Class, R, Args...>;
142 }
143
144 public:
145 /// Returns a function that accepts a void pointer, casts it to the class
146 /// type of the member function @p Method, launders it, and then invokes
147 /// @p Method with it, passing on the arguments to @p Method. The function
148 /// can also accept additional arguments at the end, of type @p ExtraArgs.
149 template <auto Method>
150 [[gnu::always_inline]] static constexpr auto invoker() {
152 }
153};
154} // namespace detail
155
156/// @copydoc detail::Launderer::invoker
157template <class Class, auto Method, class... ExtraArgs>
158[[gnu::always_inline]] constexpr auto type_erased_wrapped() {
160}
161
162template <class VTable, class Allocator>
163inline constexpr size_t default_te_buffer_size() {
164 struct S {
165 [[no_unique_address]] Allocator allocator;
166 void *self = nullptr;
167 VTable vtable;
168 };
169 const size_t max_size = 128;
170 return max_size - std::min(max_size, sizeof(S));
171}
172
173template <class... Types>
174inline constexpr size_t required_te_buffer_size_for() {
175 constexpr size_t sizes[] = {sizeof(Types)...};
176 return *std::max_element(std::begin(sizes), std::end(sizes));
177}
178
179/// Similar to `std::in_place_t`.
180template <class T>
182/// Convenience instance of @ref te_in_place_t.
183template <class T>
185
186/// Class for polymorphism through type erasure. Saves the entire vtable, and
187/// uses small buffer optimization.
188///
189/// @todo Decouple allocation/small buffer optimization.
190template <class VTable = BasicVTable,
191 class Allocator = std::allocator<std::byte>,
194 public:
195 static constexpr size_t small_buffer_size = SmallBufferSize;
197
198 private:
199 using allocator_traits = std::allocator_traits<allocator_type>;
200 using buffer_type = std::array<std::byte, small_buffer_size>;
201 [[no_unique_address]] alignas(std::max_align_t) buffer_type small_buffer;
203
204 private:
205 /// True if @p T is not a child class of @ref TypeErased.
206 template <class T>
207 static constexpr auto no_child_of_ours =
208 !std::is_base_of_v<TypeErased, std::remove_cvref_t<T>>;
209
210 protected:
211 static constexpr size_t invalid_size =
212 static_cast<size_t>(0xDEAD'BEEF'DEAD'BEEF);
213 static constexpr size_t mut_ref_size =
214 static_cast<size_t>(0xFFFF'FFFF'FFFF'FFFF);
215 static constexpr size_t const_ref_size =
216 static_cast<size_t>(0xFFFF'FFFF'FFFF'FFFE);
217 [[nodiscard]] static bool size_indicates_ownership(size_t size) {
218 return size != const_ref_size && size != mut_ref_size;
219 }
220 [[nodiscard]] static bool size_indicates_const(size_t size) {
221 return size == const_ref_size;
222 }
223
224 /// Pointer to the stored object.
225 void *self = nullptr;
226 /// Size required to store the object.
230 public:
231 /// Default constructor.
233 /// Default constructor (allocator aware).
236 /// Copy constructor.
242 /// Copy constructor (allocator aware).
247 /// Copy assignment.
249 // Check for self-assignment
250 if (&other == this)
251 return *this;
252 // Delete our own storage before assigning a new value
253 cleanup();
255 return *this;
256 }
257
258 /// Move constructor.
260 : allocator{std::move(other.allocator)} {
261 size = other.size;
262 vtable = std::move(other.vtable);
263 // If dynamically allocated, simply steal storage, or if not owned,
264 // simply move the pointer
265 if (size > small_buffer_size || !other.owns_referenced_object()) {
266 // We stole the allocator, so we can steal the storage as well
267 self = std::exchange(other.self, nullptr);
268 }
269 // Otherwise, use the small buffer and do an explicit move
270 else if (other.self) {
271 self = small_buffer.data();
272 vtable.move(other.self, self); // assumed not to throw
273 vtable.destroy(other.self); // nothing to deallocate
274 other.self = nullptr;
275 }
276 }
277 /// Move constructor (allocator aware).
279 : allocator{alloc} {
280 // Only continue if other actually contains a value
281 if (other.self == nullptr)
282 return;
283 size = other.size;
284 vtable = std::move(other.vtable);
285 // If dynamically allocated, simply steal other's storage
286 if (size > small_buffer_size) {
287 // Can we steal the storage because of equal allocators?
288 if (allocator == other.allocator) {
289 self = std::exchange(other.self, nullptr);
290 }
291 // If the allocators are not the same, we cannot steal the
292 // storage, so do an explicit move
293 else {
294 self = allocator.allocate(size);
295 vtable.move(other.self, self);
296 // Cannot call other.cleanup() here because we stole the vtable
297 vtable.destroy(other.self);
298 other.deallocate();
299 }
300 }
301 // If not owned, simply move the pointer
302 else if (!other.owns_referenced_object()) {
303 self = std::exchange(other.self, nullptr);
304 }
305 // Otherwise, use the small buffer and do an explicit move
306 else if (other.self) {
307 self = small_buffer.data();
308 vtable.move(other.self, self);
309 // Cannot call other.cleanup() here because we stole the vtable
310 vtable.destroy(other.self); // nothing to deallocate
311 other.self = nullptr;
312 }
313 other.size = invalid_size;
314 }
315 /// Move assignment.
317 // Check for self-assignment
318 if (&other == this)
319 return *this;
320 // Delete our own storage before assigning a new value
321 cleanup();
322 // Check if we are allowed to steal the allocator
323 static constexpr bool prop_alloc =
324 allocator_traits::propagate_on_container_move_assignment::value;
325 if constexpr (prop_alloc)
326 allocator = std::move(other.allocator);
327 // Only assign if other contains a value
328 if (other.self == nullptr)
329 return *this;
330
331 size = other.size;
332 vtable = std::move(other.vtable);
333 // If dynamically allocated, simply steal other's storage
334 if (size > small_buffer_size) {
335 // Can we steal the storage because of equal allocators?
336 if (prop_alloc || allocator == other.allocator) {
337 self = std::exchange(other.self, nullptr);
338 }
339 // If the allocators are not the same, we cannot steal the
340 // storage, so do an explicit move
341 else {
342 self = allocator.allocate(size);
343 vtable.move(other.self, self); // assumed not to throw
344 vtable.destroy(other.self);
345 // Careful, we might have moved other.allocator!
346 auto &deallocator = prop_alloc ? allocator : other.allocator;
347 using pointer_t = typename allocator_traits::pointer;
348 auto &&other_pointer = static_cast<pointer_t>(other.self);
349 deallocator.deallocate(other_pointer, size);
350 other.self = nullptr;
351 }
352 }
353 // If not owned, simply move the pointer
354 else if (!owns_referenced_object()) {
355 self = std::exchange(other.self, nullptr);
356 }
357 // Otherwise, use the small buffer and do an explicit move
358 else if (other.self) {
359 self = small_buffer.data();
360 vtable.move(other.self, self);
361 vtable.destroy(other.self); // nothing to deallocate
362 other.self = nullptr;
363 }
364 other.size = invalid_size;
365 return *this;
366 }
367
368 /// Destructor.
370
371 /// Main constructor that type-erases the given argument.
372 template <class T, class Alloc>
373 explicit TypeErased(std::allocator_arg_t, const Alloc &alloc, T &&d)
374 : allocator{alloc} {
375 construct_inplace<std::remove_cvref_t<T>>(std::forward<T>(d));
376 }
377 /// Main constructor that type-erases the object constructed from the given
378 /// argument.
379 template <class T, class Alloc, class... Args>
380 explicit TypeErased(std::allocator_arg_t, const Alloc &alloc,
382 : allocator{alloc} {
383 construct_inplace<std::remove_cvref_t<T>>(std::forward<Args>(args)...);
384 }
385 /// @copydoc TypeErased(std::allocator_arg_t, const Alloc &, T &&)
386 /// Requirement prevents this constructor from taking precedence over the
387 /// copy and move constructors.
388 template <class T>
389 requires no_child_of_ours<T>
390 explicit TypeErased(T &&d) {
391 construct_inplace<std::remove_cvref_t<T>>(std::forward<T>(d));
392 }
393 /// Main constructor that type-erases the object constructed from the given
394 /// argument.
395 template <class T, class... Args>
397 construct_inplace<std::remove_cvref_t<T>>(std::forward<Args>(args)...);
398 }
399
400 /// Construct a type-erased wrapper of type Ret for an object of type T,
401 /// initialized in-place with the given arguments.
402 template <class Ret, class T, class Alloc, class... Args>
403 requires std::is_base_of_v<TypeErased, Ret>
404 static Ret make(std::allocator_arg_t tag, const Alloc &alloc,
405 Args &&...args) {
406 Ret r{tag, alloc};
407 r.template construct_inplace<T>(std::forward<Args>(args)...);
408 return r;
409 }
410 /// Construct a type-erased wrapper of type Ret for an object of type T,
411 /// initialized in-place with the given arguments.
412 template <class Ret, class T, class... Args>
413 requires no_leading_allocator<Args...>
414 static Ret make(Args &&...args) {
415 return make<Ret, T>(std::allocator_arg, allocator_type{},
416 std::forward<Args>(args)...);
417 }
418
419 /// Check if this wrapper wraps an object. False for default-constructed
420 /// objects.
421 explicit operator bool() const noexcept { return self != nullptr; }
422
423 /// Check if this wrapper owns the storage of the wrapped object, or
424 /// whether it simply stores a reference to an object that was allocated
425 /// elsewhere.
429
430 /// Check if the wrapped object is const.
434
435 /// Get a copy of the allocator.
437
438 /// Query the contained type.
439 [[nodiscard]] const std::type_info &type() const noexcept {
440 return *vtable.type;
441 }
442
443 /// Convert the type-erased object to the given type. The type is checked
444 /// in debug builds only, use with caution.
445 template <class T>
446 T &as() & {
447 if (typeid(T) != type())
448 throw bad_type_erased_type(type(), typeid(T));
449 return *reinterpret_cast<T *>(self);
450 }
451 /// @copydoc as()
452 template <class T>
453 const T &as() const & {
454 if (typeid(T) != type())
455 throw bad_type_erased_type(type(), typeid(T));
456 return *reinterpret_cast<const T *>(self);
457 }
458 /// @copydoc as()
459 template <class T>
460 const T &&as() && {
461 if (typeid(T) != type())
462 throw bad_type_erased_type(type(), typeid(T));
463 return std::move(*reinterpret_cast<T *>(self));
464 }
465
466 /// Get a type-erased pointer to the wrapped object.
467 /// @throws alpaqa::util::bad_type_erased_constness
468 /// If the wrapped object is const.
469 /// @see @ref get_const_pointer()
470 [[nodiscard]] void *get_pointer() const {
473 return self;
474 }
475 /// Get a type-erased pointer to the wrapped object.
476 [[nodiscard]] const void *get_const_pointer() const { return self; }
477
478 /// @see @ref derived_from_TypeErased
479 template <std::derived_from<TypeErased> Child>
480 friend void derived_from_TypeErased_helper(const Child &) noexcept {
481 static constexpr bool False = sizeof(Child) != sizeof(Child);
482 static_assert(False, "not allowed in an evaluated context");
483 }
484
485 private:
486 /// Deallocates the storage when destroyed.
498
499 /// Ensure that storage is available, either by using the small buffer if
500 /// it is large enough, or by calling the allocator.
501 /// Returns a RAII wrapper that deallocates the storage unless released.
503 assert(!self);
505 assert(size > 0);
508 : allocator.allocate(size);
509 this->size = size;
510 return {this};
511 }
512
513 /// Deallocate the memory without invoking the destructor.
514 void deallocate() {
516 assert(size > 0);
518 using pointer_t = typename allocator_traits::pointer;
520 allocator.deallocate(reinterpret_cast<pointer_t>(self), size);
521 self = nullptr;
522 }
523
524 /// Destroy the type-erased object (if not empty), and deallocate the memory
525 /// if necessary.
526 void cleanup() {
527 if (!owns_referenced_object()) {
528 self = nullptr;
529 } else if (self) {
530 vtable.destroy(self);
531 deallocate();
532 }
533 }
534
535 template <bool CopyAllocator>
537 constexpr bool prop_alloc =
538 allocator_traits::propagate_on_container_copy_assignment::value;
539 if constexpr (CopyAllocator && prop_alloc)
540 allocator = other.allocator;
541 if (!other)
542 return;
543 vtable = other.vtable;
544 if (!other.owns_referenced_object()) {
545 // Non-owning: simply copy the pointer.
546 size = other.size;
547 self = other.self;
548 } else {
549 auto storage_guard = allocate(other.size);
550 // If copy constructor throws, storage should be deallocated and
551 // self set to null, otherwise the TypeErased destructor will
552 // attempt to call the contained object's destructor, which is
553 // undefined behavior if construction failed.
554 vtable.copy(other.self, self);
555 storage_guard.release();
556 }
557 }
558
559 protected:
560 /// Ensure storage and construct the type-erased object of type T in-place.
561 template <class T, class... Args>
563 static_assert(std::is_same_v<T, std::remove_cvref_t<T>>);
564 if constexpr (std::is_pointer_v<T>) {
565 T ptr{args...};
566 using Tnp = std::remove_pointer_t<T>;
567 size = std::is_const_v<Tnp> ? const_ref_size : mut_ref_size;
568 vtable = VTable{std::in_place, *ptr};
569 self = const_cast<std::remove_const_t<Tnp> *>(ptr);
570 } else {
571 // Allocate memory
572 auto storage_guard = allocate(sizeof(T));
573 // Construct the stored object
574 using destroyer = std::unique_ptr<T, noop_delete<T>>;
575 destroyer obj_guard{new (self) T{std::forward<Args>(args)...}};
576 vtable = VTable{std::in_place, static_cast<T &>(*obj_guard.get())};
577 obj_guard.release();
578 storage_guard.release();
579 }
580 }
581
582 /// Call the vtable function @p f with the given arguments @p args,
583 /// implicitly passing the @ref self pointer and @ref vtable reference if
584 /// necessary.
585 template <class Ret, class... FArgs, class... Args>
586 [[gnu::always_inline]] decltype(auto) call(Ret (*f)(const void *, FArgs...),
587 Args &&...args) const {
588 assert(f);
589 assert(self);
590 using LastArg = util::last_type_t<FArgs...>;
591 if constexpr (std::is_same_v<LastArg, const VTable &>)
592 return f(self, std::forward<Args>(args)..., vtable);
593 else
594 return f(self, std::forward<Args>(args)...);
595 }
596 /// @copydoc call
597 template <class Ret, class... FArgs, class... Args>
598 [[gnu::always_inline]] decltype(auto) call(Ret (*f)(void *, FArgs...),
599 Args &&...args) {
600 assert(f);
601 assert(self);
604 using LastArg = util::last_type_t<FArgs...>;
605 if constexpr (std::is_same_v<LastArg, const VTable &>)
606 return f(self, std::forward<Args>(args)..., vtable);
607 else
608 return f(self, std::forward<Args>(args)...);
609 }
610 /// @copydoc call
611 template <class Ret>
612 [[gnu::always_inline]] decltype(auto) call(Ret (*f)(const void *)) const {
613 assert(f);
614 assert(self);
615 return f(self);
616 }
617 /// @copydoc call
618 template <class Ret>
619 [[gnu::always_inline]] decltype(auto) call(Ret (*f)(void *)) {
620 assert(f);
621 assert(self);
624 return f(self);
625 }
626 /// @copydoc call
627 template <class Ret>
628 [[gnu::always_inline]] decltype(auto) call(Ret (*f)(const void *,
629 const VTable &)) const {
630 assert(f);
631 assert(self);
632 return f(self, vtable);
633 }
634 /// @copydoc call
635 template <class Ret>
636 [[gnu::always_inline]] decltype(auto) call(Ret (*f)(void *,
637 const VTable &)) {
638 assert(f);
639 assert(self);
642 return f(self, vtable);
643 }
644};
645
646template <class Child>
648 requires(Child c) { derived_from_TypeErased_helper(c); };
649
650} // namespace alpaqa::util
Class for polymorphism through type erasure.
void * get_pointer() const
Get a type-erased pointer to the wrapped object.
decltype(auto) call(Ret(*f)(const void *)) const
Call the vtable function f with the given arguments args, implicitly passing the self pointer and vta...
Deallocator allocate(size_t size)
Ensure that storage is available, either by using the small buffer if it is large enough,...
TypeErased & operator=(const TypeErased &other)
Copy assignment.
void construct_inplace(Args &&...args)
Ensure storage and construct the type-erased object of type T in-place.
void deallocate()
Deallocate the memory without invoking the destructor.
const void * get_const_pointer() const
Get a type-erased pointer to the wrapped object.
static constexpr size_t mut_ref_size
static constexpr size_t small_buffer_size
decltype(auto) call(Ret(*f)(const void *, FArgs...), Args &&...args) const
Call the vtable function f with the given arguments args, implicitly passing the self pointer and vta...
void cleanup()
Destroy the type-erased object (if not empty), and deallocate the memory if necessary.
static constexpr size_t invalid_size
const T && as() &&
Convert the type-erased object to the given type.
TypeErased(const TypeErased &other, allocator_type alloc)
Copy constructor (allocator aware).
decltype(auto) call(Ret(*f)(void *))
Call the vtable function f with the given arguments args, implicitly passing the self pointer and vta...
friend void derived_from_TypeErased_helper(const Child &) noexcept
static Ret make(Args &&...args)
Construct a type-erased wrapper of type Ret for an object of type T, initialized in-place with the gi...
static constexpr size_t const_ref_size
static constexpr auto no_child_of_ours
True if T is not a child class of TypeErased.
TypeErased(const TypeErased &other)
Copy constructor.
TypeErased(TypeErased &&other) noexcept
Move constructor.
bool referenced_object_is_const() const noexcept
Check if the wrapped object is const.
bool owns_referenced_object() const noexcept
Check if this wrapper owns the storage of the wrapped object, or whether it simply stores a reference...
decltype(auto) call(Ret(*f)(void *, FArgs...), Args &&...args)
Call the vtable function f with the given arguments args, implicitly passing the self pointer and vta...
decltype(auto) call(Ret(*f)(const void *, const VTable &)) const
Call the vtable function f with the given arguments args, implicitly passing the self pointer and vta...
size_t size
Size required to store the object.
const T & as() const &
Convert the type-erased object to the given type.
static bool size_indicates_const(size_t size)
TypeErased(te_in_place_t< T >, Args &&...args)
Main constructor that type-erases the object constructed from the given argument.
decltype(auto) call(Ret(*f)(void *, const VTable &))
Call the vtable function f with the given arguments args, implicitly passing the self pointer and vta...
TypeErased() noexcept(noexcept(allocator_type()))=default
Default constructor.
void do_copy_assign(const TypeErased &other)
std::allocator_traits< allocator_type > allocator_traits
T & as() &
Convert the type-erased object to the given type.
std::array< std::byte, small_buffer_size > buffer_type
TypeErased & operator=(TypeErased &&other) noexcept
Move assignment.
TypeErased(std::allocator_arg_t, const Alloc &alloc, T &&d)
Main constructor that type-erases the given argument.
static bool size_indicates_ownership(size_t size)
allocator_type get_allocator() const noexcept
Get a copy of the allocator.
void * self
Pointer to the stored object.
static Ret make(std::allocator_arg_t tag, const Alloc &alloc, Args &&...args)
Construct a type-erased wrapper of type Ret for an object of type T, initialized in-place with the gi...
TypeErased(T &&d)
Main constructor that type-erases the given argument.
TypeErased(TypeErased &&other, const allocator_type &alloc) noexcept
Move constructor (allocator aware).
const std::type_info & type() const noexcept
Query the contained type.
TypeErased(std::allocator_arg_t, const Alloc &alloc, te_in_place_t< T >, Args &&...args)
Main constructor that type-erases the object constructed from the given argument.
const std::type_info & actual_type
const std::type_info & requested_type
bad_type_erased_type(const std::type_info &actual_type, const std::type_info &requested_type, const std::string &message="")
const char * what() const noexcept override
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
constexpr size_t required_te_buffer_size_for()
constexpr auto type_erased_wrapped()
Returns a function that accepts a void pointer, casts it to the class type of the member function Met...
typename last_type< Pack... >::type last_type_t
constexpr te_in_place_t< T > te_in_place
Convenience instance of te_in_place_t.
constexpr size_t default_te_buffer_size()
Similar to std::in_place_t.
constexpr const auto inf
Definition config.hpp:85
Struct containing function pointers to all problem functions (like the objective and constraint funct...
Struct that stores the size of a polymorphic object, as well as pointers to functions to copy,...
BasicVTable(std::in_place_t, T &) noexcept
required_function_t< void(void *storage) const > copy
Copy-construct a new instance into storage.
typename optional_function< F, VTable >::type optional_function_t
An optional function includes a void pointer to self, the arguments of F, and an additional reference...
const std::type_info * type
The original type of the stored object.
typename required_function< F >::type required_function_t
A required function includes a void pointer to self, in addition to the arguments of F.
required_function_t< void()> destroy
Destruct the given instance.
required_function_t< void(void *storage)> move
Move-construct a new instance into storage.
Deallocates the storage when destroyed.
Deallocator & operator=(const Deallocator &)=delete
Deallocator(const Deallocator &)=delete
Deallocator & operator=(Deallocator &&) noexcept=delete
Deallocator(Deallocator &&o) noexcept
Deallocator(TypeErased *instance) noexcept
static constexpr auto do_invoke(V *self, Args... args, ExtraArgs...) -> R
static constexpr auto invoker()
Returns a function that accepts a void pointer, casts it to the class type of the member function Met...
static constexpr auto invoker_ovl(R(T::*)(Args...))
static constexpr auto invoker_ovl(R(T::*)(Args...) const)