// without using lambda
class Widget {
public:
bool isValidated() const;
bool isProcessed() const;
bool isArchived() const;
};
bool Widget::isValidated() const { return true; }
bool Widget::isProcessed() const { return true; }
bool Widget::isArchived() const { return true; }
class IsValAndArch {
public:
using DataType = std::unique_ptr<Widget>;
explicit IsValAndArch(DataType&& ptr) : pw(std::move(ptr)) { }
bool operator()() const {
return pw->isValidated() && pw->isArchived();
}
private:
DataType pw;
};
auto func = IsValAndArch(std::make_unique<Widget>());
lambda
auto func = [pw = std::move(pw)] { return pw->isValidated() && pw->isArchived(); };
// in C++14
std::vector<double> data;
...
auto func = [data = std::move(data)] { /* uses of data */ };
// in C++11
the absence of move capture was recognized as a shortcoming in C++11;
std::vector<double> data;
...
auto func = std::bind([](const std::vector<double>& data) { /* uses of data */},
std::move(data));