Header any_unique.h

Provides a type-erasure class to store objects of unknown types.

Examples

 1#include <clu/any_unique.h>
 2
 3int main()
 4{
 5    clu::any_unique a(1); // a holds an int
 6    a.emplace(std::in_place_type<double>, 3.14); // now a holds a double, and the previous int is destroyed
 7    a.reset(); // a holds nothing
 8
 9    struct immovable
10    {
11        immovable() = default;
12        immovable(immovable const&) = delete;
13        immovable(immovable&&) = delete;
14        immovable& operator=(immovable const&) = delete;
15        immovable& operator=(immovable&&) = delete;
16    };
17
18    clu::any_unique b(std::in_place_type<immovable>); // immovable objects can also be stored, using in_place_type
19}
class any_unique

A type erasure class that could store literally anything.

This class type erases objects and always store them on the heap. It is almost of no use but to provide a way to manage lifetime of objects with compile-time unknown types.

Public Functions

constexpr any_unique(const any_unique&) = delete

any_unique is not copyable.