C++ c++;解构函数返回值

C++ c++;解构函数返回值,c++,std,C++,Std,对不起,如果以前有人问过这个问题。我是个新手 因此,我有以下代码 template<typename K, typename V> class test_class { std::map<K, V> my_map; void add_kv_to_std_map ( K const& key, V const& val ) { // And basically, i have the following syntax;

对不起,如果以前有人问过这个问题。我是个新手

因此,我有以下代码

template<typename K, typename V>

class test_class {
    std::map<K, V> my_map;

    void add_kv_to_std_map ( K const& key, V const& val ) {

        // And basically, i have the following syntax;
        auto [it, ins] = my_map.insert_or_assign(key, val);

        // Then perform other operations.

    }
}
我真的不需要
ins
变量。是否可以在那里检索

起初,我以为我可以做这样的事情

auto [it, ] = my_map.insert_or_assign(key, val);
但我用它生了撒旦

如有任何建议,我们将不胜感激。提前谢谢

我真的不需要ins变量。有可能在那里找到它吗

没有

您可以使用一个变量名来表示它被忽略。就个人而言,我更喜欢下划线(注意,下划线是全局名称空间中的保留标识符,所以不要在那里使用它)

您可以使用
[[maybe_unused]]
属性向编译器表示绑定是有意未使用的:

[[maybe_unused]] auto [it, _] = ...

如果使用
std::tie
而不是结构化绑定,那么对于这种情况,可以使用
std::ignore

std::map<K, V>::iterator it;
std::tie(it, std::ignore) = ...
std::map::iterator;
std::tie(it,std::ignore)=。。。
我真的不需要ins变量。有可能在那里找到它吗

没有

您可以使用一个变量名来表示它被忽略。就个人而言,我更喜欢下划线(注意,下划线是全局名称空间中的保留标识符,所以不要在那里使用它)

您可以使用
[[maybe_unused]]
属性向编译器表示绑定是有意未使用的:

[[maybe_unused]] auto [it, _] = ...

如果使用
std::tie
而不是结构化绑定,那么对于这种情况,可以使用
std::ignore

std::map<K, V>::iterator it;
std::tie(it, std::ignore) = ...
std::map::iterator;
std::tie(it,std::ignore)=。。。

afaik,目前还没有。有一些关于模式匹配的建议可能会有所帮助,但现在只需要获取返回值,并使用
。首先,我知道了,我想我会坚持我现在拥有的。谢谢@cigienbtw,如果你收到关于不使用
ins
的警告,你可以使用
[[maybe_unused]]]
.afaik,目前还没有。有一些关于模式匹配的建议可能会有所帮助,但现在只需获取返回值,并使用
。首先,我知道了,我想我会坚持我现在所拥有的。谢谢@cigienbtw,如果您收到关于不使用
ins
的警告,您可以使用
[[maybe_unused]]