Implementing an iterator class for a my linked list. What is the using keyword?

Viewed 43

I believe this is relatively new that an iterator class is required to have the following tags at the top of the class:

using iterator_category = std::bidirectional_iterator_tag;
using value_type = T;
using difference_type = int;
using pointer = T*;
using reference = T&;

Why are these necessary and what are they doing behind the scenes? (if anything)

1 Answers

The using keyword is new in C++11.

In this instance, it's being used as a replacement for typedef.

Instead of writing:

typedef T value_type;

You can write this to get the same result:

using value_type = T;

See What is the logic behind the "using" keyword in C++? for more info.

Related