1 /*
  2  * =====================================================================================
  3  *
  4  *       Filename:  lvalue.c
  5  *
  6  *    Description:  test of vector being used as an lvalue
  7  *
  8  *        Version:  1.0
  9  *        Created:  11/28/2016 12:31:54 PM
 10  *       Revision:  none
 11  *       Compiler:  gcc
 12  *
 13  *         Author:  Ruben Safir (mn), ruben@mrbrklyn.com
 14  *        Company:  NYLXS Inc
 15  *
 16  * =====================================================================================
 17  */
 18 
 19 #include <iostream>
 20 #include <vector>
 21 
 22 namespace vect{
 23 
 24    /* 
 25    ¦* =====================================================================================
 26    ¦*        Class:  Lvalue
 27    ¦*  Description:  testing vector access as an lvalue
 28    ¦* =====================================================================================
 29    ¦*/
 30 
 31    template < class T >
 32       class Lvalue
 33       {
 34          public:
 35 
 36             // ====================  LIFECYCLE     =======================================
 37             Lvalue (){};                           /* constructor      */
 38             Lvalue (std::vector<T> in): _ofthings{in}{};                           /* constructor      */
 39             Lvalue ( const Lvalue &other ); /* copy constructor */
 40             ~Lvalue (){};                          /* destructor       */
 41 
 42             /* ====================  ACCESSORS     ======================================= */
 43             std::vector<T>&  ofthings(){
 44                return _ofthings;
 45             };
 46 
 47             void ofthings(std::vector<T> const vec){
 48                _ofthings = vec;
 49             };
 50             /* ====================  MUTATORS      ======================================= */
 51 
 52             /* ====================  OPERATORS     ======================================= */
 53 
 54             const Lvalue& operator = ( const Lvalue &other ); // assignment operator
 55             const T& operator [] (int index)
 56             {
 57                return (ofthings()[index]);
 58             };
 59             friend  std::ostream &operator << (std::ostream &os, const Lvalue in)
 60             {
 61                for(int i = 0; i < in._ofthings.size(); i++ ){
 62                   std::cout << i << "\t";
 63                }
 64                return os;
 65             };
 66 
 67             /* ====================  DATA MEMBERS  ======================================= */
 68          protected:
 69             std::vector<T> _ofthings;
 70 
 71          private:
 72 
 73       }; /* -----  end of template class Lvalue  ----- */
 74 
 75 };
 76 
 77 
 78 int main ( int argc, char *argv[] )
 79 {
 80 
 81    std::cout << "TEST INPUT TO VECTOR" << std::endl;
 82    std::vector<int> test {100};
 83    for(int i = 0; i<10; i++ ){
 84       test[i] = i;
 85       std::cout <<  test[i] << "\t";
 86 }
 87    std::cout << std::endl;
 88    std::cout << "TEST INPUT TO OBJECT" << std::endl;
 89    vect::Lvalue<int> test2 {test};
 90    for(int j=0, i = 10; j<10; i--, j++){
 91       test[j] = i;
 92       std::cout <<  test[j] << "\t";
 93    }
 94    std::cout << std::endl;
 95    std::cout << "__DONE__";
 96 
 97 
 98 
 99    return EXIT_SUCCESS;
100 }           /* ----------  end of function main  ---------- */