C++ iterator related question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++ iterator related question

Is the difference_type and ptrdiff_t in C++ are the same? Assume that x and y are iterator vector<int>::difference_type a = x - y; //a is ptrdiff_t, but the compiler compile with no error And Auto b = x - y; //b is ptrdiff_t If a is ptrdiff_t, why the compiler compile it with the difference_type with no problem? Sorry for my bad english

17th Sep 2018, 12:35 PM
Emi
Emi - avatar
4 Answers
+ 2
cppreference says this about difference_type: "Signed integer type (usually ptrdiff_t)" https://en.cppreference.com/w/cpp/container/vector It is common to typedef all types in your class, so you could change the underlying types if you ever need to. But at the end of the day it's all integers.
17th Sep 2018, 12:52 PM
Schindlabua
Schindlabua - avatar
+ 2
Yes!
17th Sep 2018, 1:25 PM
Schindlabua
Schindlabua - avatar
+ 1
Schindlabua means both of them have the same meaning and function right?
17th Sep 2018, 12:55 PM
Emi
Emi - avatar
+ 1
Schindlabua thx for your help bruh
17th Sep 2018, 1:55 PM
Emi
Emi - avatar