This repository contains two implementations of std::any
, a type-safe container for single values of any type, for C++11 compilers.
They are two single-file header-only libraries, thus you can
- either copy one of the two/both in your project and use/modify them straight away;
- you can install the project and consume the library through
CMake
.
See cppreference for the documentation and examples.
The first is an implementation of N4562 std::experimental::any
(merged into C++17) for C++11 compilers, originally implemented by thelink2012.
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.
You may additionally enable/disable the following preprocessor symbols (making the implementation non-standard) at CMake configuration time:
-
ANY_IMPL_ANY_CAST_MOVEABLE
: This implements a fix proposed in LWG Defect 2509. This will cause the expressionsT x = any_cast<T>(any(T()))
andT x = any_cast<T&&>(any(T()))
to perform a move intox
instead of a copy. -
ANY_IMPL_FAST_TYPE_INFO_COMPARE
: When checking if twotypeid
are the same, performs just a pointer comparision instead of the actualtype_info::operator==
comparision. Be aware this isn't recommended unless you know what you're doing.
The second is a port of boost:any
(v1.68.0
) for C++11 compilers, removing boost
dependencies. Its documentation can be found here.
Use the following commands to build, install and link the library.
With make
facilities:
$ git clone https://github.com/claudiofantacci/any
$ cd any
$ mkdir build && cd build
$ cmake ..
$ make
$ [sudo] make install
With IDE build tool facilities:
$ git clone https://github.com/claudiofantacci/any
$ cd superimpose-mesh-lib
$ mkdir build && cd build
$ cmake ..
$ cmake --build . --target ALL_BUILD --config Release
$ cmake --build . --target INSTALL --config Release
Once the library is installed, you can link it using CMake
with as little effort as writing the following line of code in your poject CMakeLists.txt
:
...
find_package(any REQUIRED)
...
target_link_libraries(<target>
[PUBLIC | PRIVATE | INTERFACE]
any::libany
any::libanyboost)
...
We have designed some test to run with CMake
to see whether everything run smoothly or not. Simply use
$ ctest [-VV]
to run all the tests.