Advertisement
Guest User

aecont.h

a guest
May 25th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #ifndef AECONT_H
  2. #define AECONT_H
  3. #include <vector>
  4. #include <algorithm>
  5. template <typename T>
  6. class alternating_endpoint_container: public std::vector<T>{
  7.     private:
  8.         typedef std::vector<T> base;
  9.         bool l = true;
  10.     public:
  11.         alternating_endpoint_container(): base(){
  12.         }
  13.         template< class Iter >
  14.         alternating_endpoint_container( Iter first, Iter last ): base(){
  15.             std::for_each( first, last, std::bind1st( std::mem_fun( &alternating_endpoint_container::insert ), this) );
  16.         }
  17.         void insert( T a ){
  18.             ( ( l = !l ) )?( base::insert( base::end(), a ) ):( base::insert( base::begin(), a ) );
  19.         }
  20.         void erase(){
  21.             ( ( l = !l ) )?( base::erase( base::begin() ) ):( base::erase( base::end() - 1 ) );
  22.         }
  23. };
  24. #endif // AECONT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement