#include <cstdlib> #include <iostream> #include <stdexcept> #include <codecogs\array\Grid.hpp> #include <ctime> using namespace std; int main(int argc, char *argv[]) { std::vector<int> v; v.push_back(7); //first dimension v.push_back(6); //second dimension v.push_back(5); //third dimension //non-default ctor Grid<int, 3> g3d(v); Grid<int, 2> g2d(g3d.front()); Grid<int, 1> g1d(g2d.back()); Grid<int, 3> cube3d(3, g3d.front()); //3 in length //all 2d dimensions are the same as g3d.front() //dimension size checking cout << "First dimension: " << g1d.size() << endl; cout << "Second dimension: " << g2d.size() << endl; cout << "Third dimension: " << g3d.size() << endl; try //bounds checking { int x = g1d.at(9); } catch(const std::out_of_range& e) { cout << "Bounds checking test: " << e.what() << endl; } srand(time(NULL)); for(int x = 0; x < 7; x++) { for(int y = 0; y < 6; y++) { for(int z = 0; z < 5; z++) { //operator[] //oppositly sorted g3d[z][y][x] = (100 - x) + (100 - y) + (100 - z); } } } cout << "Unsorted" << endl; //operators cout << (g3d[0] < g3d[1]) << endl; cout << (g3d[1] < g3d[0]) << endl; cout << (g3d[0] == g3d[0]) << endl; cout << (g3d[0] != g3d[0]) << endl; //begin/end/rbegin/rend sort(g3d.begin(), g3d.end()); cout << "Sorted" << endl; cout << (g3d[0] < g3d[1]) << endl; cout << (g3d[1] < g3d[0]) << endl; cout << (g3d[0] == g3d[0]) << endl; cout << (g3d[0] != g3d[0]) << endl; return 0; }Output:
First dimension: 7 Second dimension: 6 Third dimension: 5 Bounds checking test: vector::_M_range_check Unsorted 0 1 1 0 Sorted 1 0 1 0
#include <codecogs/array/grid.h>
| class Grid The N-dimensional grid class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template<...> bool | operator== (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline] Element-by-element comparison functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template<...> bool | operator!= (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template<...> bool | operator< (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template<...> bool | operator> (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template<...> bool | operator>= (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template<...> bool | operator<= (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Grid<T, 1, alloc> The specialization for the Grid of the first dimension |