[Boost.] Multi
Disclosure: This is not an official or accepted Boost library and is unrelated to the std::mdspan proposal. It is in the process of being proposed for inclusion in Boost and it doesn't depend on Boost libraries.
© Alfredo A. Correa, 2018-2025
Multi is a modern C++ library that provides manipulation and access of data in multidimensional arrays for both CPU and GPU memory.
#include <cassert> // for assert
#include <multi/array.hpp> // from https://gitlab.com/correaa/boost-multi or https://gitlab.com/correaa/boost-multi
namespace multi = boost::multi;
int main() {
multi::array<int, 2> A = {{1, 2, 3}, {4, 5, 6}}; // 2D array of integers
assert(A.size() == 2); // the array has 2 rows
assert(A.size() == A.end() - A.begin()); // interators to rows
assert(A[1][1] == 5); // element access through indexing
assert(A.elements().size() == 2 * 3); // array has 6 elements
assert(A.elements()[4] == 5); // elements gives "flat" sequences
}Before installing the library, you can try it online through the Godbolt's Compiler Explorer.
Multi has no external dependencies and can be used immediately after downloading.
git clone https://gitlab.com/correaa/boost-multi.gitMulti doesn't require installation since a single header is enough to use the entire core library;
#include <multi/array.hpp>
int main() { ... }The library can be also installed with CMake.
The header (and CMake) files will be installed in the chosen prefix location (by default, /usr/local/include/multi and /usr/local/share/multi).
cd boost-multi
mkdir -p build && cd build
cmake . -B ./build # --install-prefix=$HOME/.local
cmake --install ./build # or sudo ...Testing the library requires Boost.Core (headers), installed for example, via sudo apt install cmake git g++ libboost-test-dev make or sudo dnf install boost-devel cmake gcc-c++ git.
A CMake build system is provided to compile and run basic tests.
ctest -C ./buildOnce installed, other CMake projects (targets) can depend on Multi by adding a simple add_subdirectory(my_multi_path) or by find_package:
find_package(multi) # see https://gitlab.com/correaa/boost-multiAlternatively, the library can be fetched on demand:
include(FetchContent)
FetchContent_Declare(multi GIT_REPOSITORY https://gitlab.com/correaa/boost-multi.git)
FetchContent_MakeAvailable(multi)
...
target_link_libraries(my_target PUBLIC multi)- File a Gitlab issue or Github issue.
- Join the #boost-multi discussion group at cpplang.slack.com