I have forgotten

COST (GBP)
1.22
0.00
0

# grid

A stl-compliant N-dimensional grid class
Controller: samtheman

C++

## Overview

A N-dimensional grid class. It has the same interface and time complexity as vectors do. Having said that, construction can be slightly different and the time complexity for functions that are linear for the vector are actually O(N^dimensions) because each linear time function performs the same linear time function on each element, and so forth.

### Example 1

```#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```

### Authors

Sam Schetterer (June 2007)

## Class Grid

A N-dimensional grid class.
##### Source Code

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.

## Members of Grid

#### Resize

 voidresize( size_type length value_type val` = value_type()` )
 val Default value = value_type()

## Operator==

 template<...> booloperator==( const Grid<...>& a const Grid<...>& b )[inline]

### Authors

Sam Schetterer (June 2007)
##### Source Code

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.

## Class Grid

### Authors

Sam Schetterer (June 2007)
##### Source Code

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.

## Members of Grid<T, 1, alloc>

#### Resize

 voidresize( size_type length value_type val` = value_type()` )
 val Default value = value_type()