Here are the fragments of my linked_list template :
template < class T , class Allocator = std::allocator< T > >
class linked_list final
{/*... */
enum constantness { CONST , MUTABLE } ;
template< constantness is_const >
class iterator_base : public std::iterator< std::bidirectional_iterator_tag , node< T > , std::ptrdiff_t ,
typename std::conditional< is_const == MUTABLE , T * , const T * >::type ,
typename std::conditional< is_const == MUTABLE , T& , const T& >::type >
{ /* ... */
typename std::iterator_traits< iterator_base >::pointer operator -> () const { return &( to_obj_node( current_node_ ) -> object() ) ; }
typename std::iterator_traits< iterator_base >::reference operator * () const { return to_obj_node( current_node_ ) -> object() ; }
/* ... */
} ;
public : /* types : */
/* ... */
using iterator = iterator_base< MUTABLE > ;
using const_iterator = iterator_base< CONST > ;
/* I */using difference_type = typename std::iterator_traits< iterator >::difference_type ;
/* II */using difference_type = std::ptrdiff_t ;
/* ... */
} ;
int main( void )
{
linked_list< int > list{ 1 , 2 , 5 , 7 , 8 , 4 } ;
auto it = list.begin() ;
* it = 9 ;
return 0 ;
}
When I leave line that's marked first uncommented, the code doesn't compile.
g++5.4 :
list2.cxx:105:66: error: no type named ‘pointer’ in ‘struct std::iterator_traits<linked_list<int>::iterator_base<(linked_list<int, std::allocator<int> >::constantness)1u> >’
typename std::iterator_traits< iterator_base >::pointer operator -> () const { return &( to_obj_node( current_node_ ) -> object() ) ; }
icpc :
list.cxx(105): error: incomplete type is not allowed typename std::iterator_traits< iterator_base >::pointer operator -> () const { return &( to_obj_node( current_node_ ) -> object() ) ; }
With second line all compiles fine.
Aucun commentaire:
Enregistrer un commentaire