Hi, I'm going through Scott Meyers "Effective C++, 3rd Edition", and it gives some of the vital details for using iterator traits, but 100% fails to detail HOW to instantiate the traits.
For example, if I create a custom container with a custom iterator, I know that I can make a nested class and make a typedef of the type of iterator the template class supports.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
template <typename T>
class MyContainer
{
public:
//cons/dtors
class iterator
{
public:
typedef std::bidirectional_iterator_tag iterator_category;
};
private:
//impl details
};
|
I've checked out the iterator_traits class and I see how it simply copies the nested typedef into its own typedef.
The question I have is.... HOW?!
How the bonk do I link my class to the iterator_traits class?
WHY and HOW?
I've tried adding this to the end of my header to try and instantiate the custom traits class~
1 2 3 4
|
std::iterator_traits<MyClass>
//also tried
std::iterator_traits<MyClass<int>>
//tried both with defining names as well
|
But they give directionless errors all over the place.
I've tried googling all around but only find text-book copied explanations (which makes me suspect most of the people responding with such don't understand how it works either).
I'm literally enraged at how the book could leave out how to friggin' instantiate all of this information....
Any help would be appreciated, especially a simple code sample showing how to use iterator_traits.
Thanks :(