gpt4 book ai didi

c++ - 将 `std::unordered_map` 值放入 `std::pair`

转载 作者:太空狗 更新时间:2023-10-29 20:37:07 28 4
gpt4 key购买 nike

<分区>

我正在尝试将值放入 std::unordered 映射中,如下所示:

std::unordered_map<std::string, std::pair<std::string, std::string>> testmap;
testmap.emplace("a", "b", "c"));

这不起作用,因为:

error C2661: 'std::pair::pair' : no overloaded function takes 3 arguments

我看过this answerthis answer ,似乎我需要将 std::piecewise_construct 合并到安置中才能使其正常工作,但我认为在这种情况下我不太清楚该把它放在哪里。尝试像

这样的事情
testmap.emplace(std::piecewise_construct, "a", std::piecewise_construct, "b", "c"); // fails
testmap.emplace(std::piecewise_construct, "a", "b", "c"); // fails
testmap.emplace(std::piecewise_construct, "a", std::pair<std::string, std::string>( std::piecewise_construct, "b", "c")); // fails

有什么方法可以让这些值emplace吗?

我正在使用 msvc2013 进行编译以防万一。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com