Skip to content

claudiofantacci/any

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Any

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

  1. either copy one of the two/both in your project and use/modify them straight away;
  2. you can install the project and consume the library through CMake.

See cppreference for the documentation and examples.

📚 libany::any

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 expressions T x = any_cast<T>(any(T())) and T x = any_cast<T&&>(any(T()))to perform a move into x instead of a copy.

  • ANY_IMPL_FAST_TYPE_INFO_COMPARE: When checking if two typeid are the same, performs just a pointer comparision instead of the actual type_info::operator== comparision. Be aware this isn't recommended unless you know what you're doing.

📚 libanyboost::any

The second is a port of boost:any (v1.68.0) for C++11 compilers, removing boost dependencies. Its documentation can be found here.

🔨 Build and link the library

Use the following commands to build, install and link the library.

Build

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

Link

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)
...

🔬 Test the library

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.


how-to-export-cpp-library

Releases

No releases published

Packages

No packages published