Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

C++20 module
PrevUpHomeNext
[Caution] Caution

C++20 module support is on early stage, targets, flags and behavior may change in the future

If using modern CMake define CMake option -DBOOST_USE_MODULES=1 to build a C++20 module and make the Boost::type_index CMake target provide it. After that an explicit usage of C++20 module boost.type_index is allowed:

#include <iostream>

import boost.type_index;

int main() {
    std::cout << boost::typeindex::type_id_with_cvr<const int>();  // Outputs: const int
}

The Boost::type_index CMake target gives an ability to mix includes and imports of the library in different translation units. Moreover, if BOOST_USE_MODULES macro is defined then all the boost/type_index/... includes implicilty do import boost.type_index; to give all the benifits of modules without changing the existing code.

[Note] Note

For better compile times make sure that import std; is available when building the boost.type_index module (in CMake logs there should be a 'Using import std;' message).

If not using CMake, then the module could be build manually from the modules/boost_type_index.cppm file.

For manual module build the following commands can be used for clang compiler:

cd type_index/modules
clang++ -I ../include -std=c++20 --precompile -x c++-module boost_type_index.cppm

After that, the module could be used in the following way:

clang++ -std=c++20 -fmodule-file=boost_type_index.pcm boost_type_index.pcm usage_sample.cpp

PrevUpHomeNext