dimanche 1 mai 2016

using a templated key in std::unordered_map

I don't understand why my compiler won't accept code below

#include <unordered_set>
#include <unordered_map>

template<class T>
using M = std::unordered_set<T>;

template<class T>
using D = M<T>;

template<class T>
using DM = std::unordered_map < typename M<T>::const_iterator    // Problem
                              , typename D<T>::const_iterator >; // Problem

int main(int argc, char ** argv)
{
    D<int> d;
    M<int> m;
    DM<int> dm; // Problem
}

The compiler command is

clang++ -std=c++14 test.cpp -o test

A compiler error message excerpt is

/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.1/../../../../include/c++/5.3.1/bits/hashtable_policy.h:85:11: error: 
      implicit instantiation of undefined template
      'std::hash<std::__detail::_Node_const_iterator<int, true, false> >'
        noexcept(declval<const _Hash&>()(declval<const _Key&>()))>

Why isn't it allowed to use typename M<T>::const_iterator as key in std::unordered_map?

Aucun commentaire:

Enregistrer un commentaire