相关疑难解决方法(0)

请解释一下使用std :: ignore的代码

我正在阅读std::ignorecppreference 的文档.我发现很难掌握这个对象的真正目的,并且示例代码并没有做到这一点.例如,在下面的代码中,如何以及为什么inserted设置为true?这对我来说没什么意义.

#include <iostream>
#include <string>
#include <set>
#include <tuple>

int main()
{
    std::set<std::string> set_of_str;
    bool inserted;
    std::tie(std::ignore, inserted) = set_of_str.insert("Test");
    if (inserted) {
        std::cout << "Value was inserted sucessfully\n";
    }
}
Run Code Online (Sandbox Code Playgroud)

如果有人可以向我解释代码,我们将不胜感激.谢谢.

c++ c++11

27
推荐指数
2
解决办法
4061
查看次数

包装std :: ignore

我正在开发一个自定义库.到目前为止,我已将std :: tuple和std :: tie包装到我自己的myOwn :: Tuple和myOwn :: tie中.它们的功能与std :: tuple和std :: tie相同.我想用std :: ignore做类似的事情.

到目前为止,我写了以下内容:

namespace myOwn
{
     auto
     tilde()
     -> decltype(std::ignore)
     {
         return std::ignore;
     }
}
Run Code Online (Sandbox Code Playgroud)

我唯一的问题是我现在必须使用带圆括号的myOwn :: tilde().我希望能够将其用作myOwn :: tilde.到目前为止,我在std :: ignore上读到的只是如何使用它,

这里:std :: ignore的可能实现

这里:std :: ignore的要求

在这里:C++:使用std :: ignore返回std :: tie的类型

我试过用了

typedef std::ignore tilde
Run Code Online (Sandbox Code Playgroud)

但这没有成功.任何帮助,将不胜感激.这个问题可能对试图包装对象的其他人有用.

c++ stl std wrapper c++11

1
推荐指数
1
解决办法
159
查看次数

标签 统计

c++ ×2

c++11 ×2

std ×1

stl ×1

wrapper ×1