Boost.Multi provides owning multidimensional arrays containers and non-owning multidimensional views for C++17. It supports slicing, layout transformations, and CPU/GPU memory.
Project status: Boost.Multi is not an official or accepted Boost library. It is being proposed for inclusion in Boost and has no Boost-library dependencies.
© Alfredo A. Correa, 2018–2026
- Generic element type and dimensionality
- Natural multidimensional access: write
A[i][j]...or iterate recursively over rows, subarrays or elements. - Composable subarray views: slice, transpo se, rotate indices, and broadcast arrays without copying their elements.
- Interoperability: use standard algorithms (iterators and ranges), allocators, and legacy libraries for strided arrays (BLAS, FFTW, CUDA, HIP, MPI, etc.)
git clone https://github.com/correaa/boost-multi.git # or gitlab.com/correaa/boost-multi.git cd boost-multi cmake -S . -B build cmake --build build ctest --test-dir build --output-on-failure
Read the documentation or explore test/.
#include <cassert> #include <multi/array.hpp> namespace multi = boost::multi; int main() { multi::array<int, 2> A = { {1, 2, 3}, {4, 5, 6} }; assert(A[1][1] == 5); // ordinary multidimensional indexing using multi::_; auto&& second_column = A(_, 1); // a non-owning view second_column[0] = 20; // changes A[0][1] assert(A[0][1] == 20); }
Try the library online with Godbolt's Compiler Explorer.
Add the repository's include/ directory to your compiler's include path and include the headers you need:
#include <multi/array.hpp>
Alternatively, download the single amalgamated header and include it as #include <boost-multi.hpp>.
Add Multi from an in-tree source directory and link its interface target:
add_subdirectory(path/to/boost-multi) target_link_libraries(my_target PRIVATE multi)
Fetch Multi on demand:
include(FetchContent) FetchContent_Declare(multi GIT_REPOSITORY https://gitlab.com/correaa/boost-multi.git) FetchContent_MakeAvailable(multi) target_link_libraries(my_target PRIVATE multi)
Testing requires Boost.Test. For example, install libboost-test-dev on Debian/Ubuntu or boost-devel on Fedora.
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure- File a Gitlab issue or Github issue.
- Join the #boost-multi discussion group at cpplang.slack.com