Are there guidelines on how one should write new container which will behave like any STL container?
Are there guidelines on how one should write new container which will behave like
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Here’s a sequence pseudo-container I pieced together from § 23.2.1\4 Note that the
iterator_categoryshould be one ofstd::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.Also, whenever I make a container, I test with a class more or less like this:
Make containers of
testerobjects, and call each one’sfunction()as you test your container. Do not make any globaltesterobjects. If your container cheats anywhere, thistesterclass willassertand you’ll know that you cheated accidentally somewhere.