Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 构造函数中的Lambda_C++ - Fatal编程技术网

C++ 构造函数中的Lambda

C++ 构造函数中的Lambda,c++,C++,我有一个在其构造函数中使用lambda的类,我很难理解它是如何执行的 using pred = std::function<bool(int)>; using pred_list = std::vector<pred>; class check { private: std::string const _description; public: check(std::string, msec duration = msec

我有一个在其构造函数中使用lambda的类,我很难理解它是如何执行的

using pred = std::function<bool(int)>;
using pred_list = std::vector<pred>;

class check
{
    private:
        std::string const _description;
    public:
        check(std::string, msec duration = msec{0});
        check(std::string, pred_list, msec duration = msec{0});
        check(std::string, pred, msec duration = msec{0});
};
有关建造商

check::check(std::string s, msec dur)
: check(s, [](int i) { return i > 0; }, dur) 
{};
如果我创建一个类型为check的对象,请使用以下命令

check db_intl{"Test", db_dur};
调用以下构造函数

check::check(std::string s, msec dur)
: check(s, [](int i) { return i > 0; }, dur) 
{};

如果lambda没有被使用,这个构造函数如何调用另一个具有lambda的构造函数?

由于
pred
被类型化为
std::function
,lambda将被转换为
pred
,然后构造被委托给第三个构造函数(
检查(std::string,pred,msec duration=msec{0}
。然后,lambda将存储在
\u谓词
容器中,并(可能)在稍后调用谓词时调用。

\u谓词被定义为
pred\u list const\u谓词;
如果我创建一个类型为check的对象,如
check db\u intl{“Test”,db\u dur};
它只传递2个参数,在第三个构造函数中没有可用于lambda@zer0c00l双参数构造函数将委托给三参数构造函数;请参阅上的“委托构造函数”部分。lambda未使用任何局部变量。
check::check(std::string s, msec dur)
: check(s, [](int i) { return i > 0; }, dur) 
{};