This is a implementation of N4562 std::experimental::any (merged into C++17) for C++11 compilers.
It contains a small object optimization for objects with a size of up to 2 words (such as int
, float
and std::shared_ptr
). Storing those objects in the container will not trigger a dynamic allocation.
For a easy to understand documentation, see cppreference, except our namespace is linb
.
You may additionally define the following preprocessor symbols (making the implementation non-standard):
ANY_IMPL_NO_EXCEPTIONS
: This disables code paths that throw exceptions.ANY_IMPL_NO_RTTI
: This disablesany::type()
, thus removing all code paths using RTTI.ANY_IMPL_FAST_TYPE_INFO_COMPARE
: When checking if twotypeid
are the same, performs just a pointer comparison instead of the actualtype_info::operator==
comparison. Be aware this isn't recommended since objects passed across library boundaries mayn't compare equal. This has no effect ifANY_IMPL_NO_RTTI
is defined.