Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations

Shows how to create containers for which the rank (or dimension) can be set at runtime (not defined at compile-time).

#include <iostream>
#include <tr1/array> // TR1 array
#include <spatial/point_multiset.hpp>
// Using a rank of 0 for the container, allows you to determine the dimension at
// runtime, as a parameter of the constructor of the conatiner.
int main(int, char**)
// Dimension of 0: This container's rank (or dimension) will be determined at
// runtime
std::cout << "Enter a dimension for container: " << std::flush;
std::cin >> dim;
// If we are not interested in dealing with ranks larger than 20
if (dim >= 20) throw spatial::invalid_dimension("dim");
runtime_container container(dim); // Note: if dim was equal to 0,
// spatial::invalid_dimension would be
// thrown
std::cout << "container rank is: " << container.dimension() << std::endl;
return 0;