jeudi 13 juillet 2017

decltype of iterator as template argument

Below is a simplified code to replicate my problem:

Working code:

int main(int argc, char **argv)
{
    std::vector<int> x;
    std::map<char, std::vector<int>::size_type> y;
    y[0]=x.size();
    return 0;
}

Not working code (using decltype):

int main(int argc, char **argv)
{
    std::vector<int> x;
    //std::map<char, std::vector<int>::size_type> y;
    std::map<char, decltype(x.begin())> y;
    y[0]=x.size();
    return 0;
}

The code fails to compile with the following error:

error: no match for ‘operator=’ (operand types are ‘std::map > >::mapped_type {aka __gnu_cxx::__normal_iterator >}’ and ‘std::vector::size_type {aka long unsigned int}’) y[0]=x.size();

Shouldn't decltype(x.begin()) be equivalent to std::vector<int>::size_type?

Aucun commentaire:

Enregistrer un commentaire