Advertisement
Guest User

aecont.h

a guest
May 25th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 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.     bool l = true;
  9. public:
  10.     alternating_endpoint_container():std::vector<T>(){
  11.     }
  12.     template< class Iter >
  13.     alternating_endpoint_container( Iter first, Iter last ):std::vector<T>(){
  14.         std::for_each( first, last, std::bind1st( std::mem_fun( &alternating_endpoint_container::insert ), this) );
  15.     }
  16.     void insert( T a ){
  17.         ( ( l = !l ) )?( std::vector<T>::insert( std::vector<T>::end(), a ) ):( std::vector<T>::insert( std::vector<T>::begin(), a ) );
  18.     }
  19.     void erase(){
  20.         ( ( l = !l ) )?( std::vector<T>::erase( std::vector<T>::begin() ) ):( std::vector<T>::erase( std::vector<T>::end() - 1 ) );
  21.     }
  22. };
  23. #endif // AECONT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement