V
V
Valery Dmitriev2014-06-05 19:04:23
C++ / C#
Valery Dmitriev, 2014-06-05 19:04:23

What is the difference between forward_list::iterator and _Fwd_list_iterator?

I'm probably dumb, but I can't figure out what's wrong.
The following code compiles without problems:

#include <forward_list>
template<typename T>
class Foo
{
    std::_Fwd_list_const_iterator<T> cur;
    //...
};

The following one throws an error:
#include <forward_list>
template<typename T>
class Foo
{
    std::forward_list<T>::const_iterator cur;
    //...
};

$ g++ -c -std=c++11 1.cpp
1.cpp:5:5: error: need ‘typename’ before ‘std::forward_list<T>::const_iterator’ because ‘std::forward_list<T>’ is a dependent scope
     std::forward_list<T>::const_iterator cur;
     ^

$ clang++ -c -std=c++11 1.cpp
1.cpp:5:5: error: missing 'typename' prior to dependent type name 'std::forward_list<T>::const_iterator'
    std::forward_list<T>::const_iterator cur;
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    typename 
1 error generated.

Fwd_list_const_iterator is defined in libstdc++ like this: (see https://gcc.gnu.org/onlinedocs/gcc-4.6.4/libstdc++...
typedef _Fwd_list_const_iterator<_Tp>           const_iterator;

Any ideas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
malerix, 2014-06-05
@rotor

The compiler prompts you: you need to add "typename".
Here you can read about it.
It works:

#include <forward_list>
template<typename T>
class Foo
{
    typename std::forward_list<T>::const_iterator cur;
};

H
Hertz, 2014-06-18
@Hertz

_Fwd_list_const_iterator is an internal implementation detail of libstdc++, you shouldn't use it at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question