L'exemple minimal suivant :
#include <iostream>
#include <boost/unordered_map.hpp>
int main()
{
boost::unordered_map<int, int> m;
boost::unordered_map<int, int>::const_iterator i;
m.insert(std::make_pair(1, 2));
i = m.end();
--i;
std::cout << i->first << " -> " << i->second << std::endl;
return 0;
}
...ne parvient pas à compiler.
bidi.cxx: In function ‘int main()’:
bidi.cxx:13: error: no match for ‘operator--’ in ‘--i’
Selon Documentation propre à Boost :
iterator
,const_iterator
sont au moins de la catégorie avant.
Il semblerait que ce soit tout ce qu'ils sont. Pourquoi ? Quelle restriction technique une carte de hachage impose-t-elle qui empêche les itérateurs d'être bidirectionnels ?
(gcc version 4.1.2, Boost versions 1.40.0 et 1.43.0).