Using a std::tuple as key for std::unordered_map

前端 未结 2 495
一个人的身影
一个人的身影 2020-12-29 10:54

With the code below, I get a very confusing error in MSVC that seems to suggest the key type (an std::tuple) is being converted to an std::string.

#include &         


        
相关标签:
2条回答
  • 2020-12-29 11:35

    Strange. Your code works fine in Visual Studio 2012 RC and output is "x: test data".

    0 讨论(0)
  • 2020-12-29 11:48

    The problem for ideone is that key_t already exists:

    prog.cpp:7:42: error: conflicting declaration 'typedef class std::tuple<std::basic_string<char>, int, char> key_t'
    /usr/include/sys/types.h:123:17: error: 'key_t' has a previous declaration as 'typedef __key_t key_t'
    

    Rename your key_t to something else, or put it into some namespaces.

    Your code works after this change in both g++ and clang++. I believe this is a bug in MSVC.

    0 讨论(0)
提交回复
热议问题