Or login with:
#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
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
| template<...> booloperator==( | const Grid<...>& | a | |
| const Grid<...>& | b | )[inline] |
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
You must login to leave a messge