Advertisement
konalisp

vector shit

Mar 17th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4.  
  5. //This document uses tabs of length 4.
  6. //Compile with the C++11 standard.
  7.  
  8. using namespace std;
  9. const int to_ashes = 0;
  10.  
  11. typedef vector<vector<vector<int>>> i3d; //3-Dimensional vector of integers, thus the name.
  12.  
  13. function<i3d(int,int,int)> retVec = [](int x, int y, int z) -> i3d {
  14.     i3d vec;
  15.     vec.resize(x);
  16.     for(int a = 0; a < x; ++a){ //this mess actually tells the vectors their size.
  17.         vec[a].resize(y);       //accessing a vector will segfault if you don't do this.
  18.         for(int b = 0; b < x; ++b)
  19.             vec[a][b].resize(z);
  20.     }
  21.     return vec;
  22. };
  23.  
  24. class Vec3D {
  25.     //The entire purpose of this class is because I hate writing
  26.     //out vec[val][val][val] instead of simply vec(val,val,val).
  27.     protected:
  28.         i3d vec;
  29.     public:
  30.         Vec3D(int x, int y, int z) {
  31.             vec = retVec(x,y,z);
  32.         };
  33.        
  34.         /*inline int& at(int x, int y, int z) {
  35.             return vec[x][y][z];
  36.         }*/
  37.        
  38.         function<int&(int,int,int)> at = [this](int x, int y, int z) -> int& {
  39.             return this->vec[x][y][z];
  40.         };
  41. };
  42.  
  43. int main(int argc, char **argv) {
  44.    
  45.     Vec3D vec(4,4,4);
  46.    
  47.     vec.at(0,0,1) = 13;
  48.    
  49.     cout << vec.at(0,0,1) \
  50.          << endl \
  51.          << vec.at(0,0,0) \
  52.          << endl;
  53.    
  54.     return to_ashes;
  55.     //the woods decay, the woods decay and fall
  56.     //the vapours weep their burthen to the ground
  57.     //man comes and tills the soil and lies beneath
  58.     //and after many a summer dies the swan.
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement