std::distacne
此代码段有什么问题?
据我所知,对于std::map
or std::vector
,可以调用std::distance
. std::distance
但是对于这个代码片段,如果被调用,程序就会崩溃。
// constructing unordered_multisets
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_multiset<std::string> sixth ( {"red","green","blue"} ); // range
auto itr = sixth.begin();
itr++;
int dis = std::distance(itr, sixth.begin()); //What's wrong?!
std::cout << ">>"<< dis << std::endl;
std::cout << "game over" << std::endl;
return 0;