c++ stl traits const T* partial specialization.
PHPz
PHPz 2017-05-16 13:30:50
0
1
1038

as follows:

template <class I>
struct iterator_traits
{
    typedef typename I::value_type   value_type;
}
//针对指向常数对象的指针的特例化
template <class T>
struct iterator_traits<const T*>
{
    typedef T  value_type;
}

I think of getting the value_type related to the iterator. Why convert const int to int? What we want to get is type information. Although the obtained (variable of this type) cannot be modified, why is it said to be useless (said in the stl source code analysis book)

Above, I hope you can help me explain. Thank you.

PHPz
PHPz

学习是最好的投资!

reply all(1)
漂亮男人
  1. That’s it, the purpose of traits (extraction) is to statically obtain some inherent characteristics of the object at compile time

  2. I don’t quite understand what you want to express. You said “Why convert const int to int”? In fact, const is defined by the following

template <class T>
struct iterator_traits<const T*>
{
    typedef const T  const_value_type;
    //你可以定义更多的,traits出更多的类型
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template