Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:57:35+00:00 2026-05-26T04:57:35+00:00

Are there guidelines on how one should write new container which will behave like

  • 0

Are there guidelines on how one should write new container which will behave like any STL container?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:57:36+00:00Added an answer on May 26, 2026 at 4:57 am

    Here’s a sequence pseudo-container I pieced together from § 23.2.1\4 Note that the iterator_category should be one of std::input_iterator_tag, std::output_iterator_tag,std::forward_iterator_tag,std::bidirectional_iterator_tag,std::random_access_iterator_tag. Also note that the below is technically more strict than required, but this is the idea. Note that the vast majority of the “standard” functions are technically optional, due to the awesomeness that is iterators.

    template <class T, class A = std::allocator<T> >
    class X {
    public:
        typedef A allocator_type;
        typedef typename A::value_type value_type; 
        typedef typename A::reference reference;
        typedef typename A::const_reference const_reference;
        typedef typename A::difference_type difference_type;
        typedef typename A::size_type size_type;
    
        class iterator { 
        public:
            typedef typename A::difference_type difference_type;
            typedef typename A::value_type value_type;
            typedef typename A::reference reference;
            typedef typename A::pointer pointer;
            typedef std::random_access_iterator_tag iterator_category; //or another tag
    
            iterator();
            iterator(const iterator&);
            ~iterator();
    
            iterator& operator=(const iterator&);
            bool operator==(const iterator&) const;
            bool operator!=(const iterator&) const;
            bool operator<(const iterator&) const; //optional
            bool operator>(const iterator&) const; //optional
            bool operator<=(const iterator&) const; //optional
            bool operator>=(const iterator&) const; //optional
    
            iterator& operator++();
            iterator operator++(int); //optional
            iterator& operator--(); //optional
            iterator operator--(int); //optional
            iterator& operator+=(size_type); //optional
            iterator operator+(size_type) const; //optional
            friend iterator operator+(size_type, const iterator&); //optional
            iterator& operator-=(size_type); //optional            
            iterator operator-(size_type) const; //optional
            difference_type operator-(iterator) const; //optional
    
            reference operator*() const;
            pointer operator->() const;
            reference operator[](size_type) const; //optional
        };
        class const_iterator {
        public:
            typedef typename A::difference_type difference_type;
            typedef typename A::value_type value_type;
            typedef typename const A::reference reference;
            typedef typename const A::pointer pointer;
            typedef std::random_access_iterator_tag iterator_category; //or another tag
    
            const_iterator ();
            const_iterator (const const_iterator&);
            const_iterator (const iterator&);
            ~const_iterator();
    
            const_iterator& operator=(const const_iterator&);
            bool operator==(const const_iterator&) const;
            bool operator!=(const const_iterator&) const;
            bool operator<(const const_iterator&) const; //optional
            bool operator>(const const_iterator&) const; //optional
            bool operator<=(const const_iterator&) const; //optional
            bool operator>=(const const_iterator&) const; //optional
    
            const_iterator& operator++();
            const_iterator operator++(int); //optional
            const_iterator& operator--(); //optional
            const_iterator operator--(int); //optional
            const_iterator& operator+=(size_type); //optional
            const_iterator operator+(size_type) const; //optional
            friend const_iterator operator+(size_type, const const_iterator&); //optional
            const_iterator& operator-=(size_type); //optional            
            const_iterator operator-(size_type) const; //optional
            difference_type operator-(const_iterator) const; //optional
    
            reference operator*() const;
            pointer operator->() const;
            reference operator[](size_type) const; //optional
        };
    
        typedef std::reverse_iterator<iterator> reverse_iterator; //optional
        typedef std::reverse_iterator<const_iterator> const_reverse_iterator; //optional
    
        X();
        X(const X&);
        ~X();
    
        X& operator=(const X&);
        bool operator==(const X&) const;
        bool operator!=(const X&) const;
        bool operator<(const X&) const; //optional
        bool operator>(const X&) const; //optional
        bool operator<=(const X&) const; //optional
        bool operator>=(const X&) const; //optional
    
        iterator begin();
        const_iterator begin() const;
        const_iterator cbegin() const;
        iterator end();
        const_iterator end() const;
        const_iterator cend() const;
        reverse_iterator rbegin(); //optional
        const_reverse_iterator rbegin() const; //optional
        const_reverse_iterator crbegin() const; //optional
        reverse_iterator rend(); //optional
        const_reverse_iterator rend() const; //optional
        const_reverse_iterator crend() const; //optional
    
        reference front(); //optional
        const_reference front() const; //optional
        reference back(); //optional
        const_reference back() const; //optional
        template<class ...Args>
        void emplace_front(Args&&...); //optional
        template<class ...Args>
        void emplace_back(Args&&...); //optional
        void push_front(const T&); //optional
        void push_front(T&&); //optional
        void push_back(const T&); //optional
        void push_back(T&&); //optional
        void pop_front(); //optional
        void pop_back(); //optional
        reference operator[](size_type); //optional
        const_reference operator[](size_type) const; //optional
        reference at(size_type); //optional
        const_reference at(size_type) const; //optional
    
        template<class ...Args>
        iterator emplace(const_iterator, Args&&...); //optional
        iterator insert(const_iterator, const T&); //optional
        iterator insert(const_iterator, T&&); //optional
        iterator insert(const_iterator, size_type, T&); //optional
        template<class iter>
        iterator insert(const_iterator, iter, iter); //optional
        iterator insert(const_iterator, std::initializer_list<T>); //optional
        iterator erase(const_iterator); //optional
        iterator erase(const_iterator, const_iterator); //optional
        void clear(); //optional
        template<class iter>
        void assign(iter, iter); //optional
        void assign(std::initializer_list<T>); //optional
        void assign(size_type, const T&); //optional
    
        void swap(X&);
        size_type size() const;
        size_type max_size() const;
        bool empty() const;
    
        A get_allocator() const; //optional
    };
    template <class T, class A = std::allocator<T> >
    void swap(X<T,A>&, X<T,A>&); //optional
    

    Also, whenever I make a container, I test with a class more or less like this:

    #include <cassert>
    struct verify;
    class tester {
        friend verify;
        static int livecount;
        const tester* self;
    public:
        tester() :self(this) {++livecount;}
        tester(const tester&) :self(this) {++livecount;}
        ~tester() {assert(self==this);--livecount;}
        tester& operator=(const tester& b) {
            assert(self==this && b.self == &b);
            return *this;
        }
        void cfunction() const {assert(self==this);}
        void mfunction() {assert(self==this);}
    };
    int tester::livecount=0;
    struct verify {
        ~verify() {assert(tester::livecount==0);}
    }verifier;
    

    Make containers of tester objects, and call each one’s function() as you test your container. Do not make any global tester objects. If your container cheats anywhere, this tester class will assert and you’ll know that you cheated accidentally somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any guidelines on when you should and should not write a long
This is a continuation of questions like this one . Are there any guidelines
Are there any guidelines/best practices for deciding what type of data should be stored
Is there any pdf which tells about coding guidelines in objective C. For Example...
Are there any standards (HTML, UI, accessibility, and such like) that stipulate that one
Is there any sort of guidelines or best practices on how release notes should
Are there any guidelines on writing database tests so that you can refactor database
Are there any guidelines to writing Google App Engine Python code that would work
Is there any guidelines on how to differentiate between .nil? , .blank? and .empty?
Is there any guidelines to convert Table design to Div design keeping same cross

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.