Cannot get the commented lambda to work. Could only work out how to do this using a good-old functor. Can it be done?
#include <initializer_list>
#include <iostream>
#include <algorithm>
#include <string>
struct find_first_not_of
{
find_first_not_of(std::string const& str) : str_(str) {}
bool operator()(char ch) const {
auto f = str_.find(ch);
return f == std::string::npos;
}
const std::string& str_;
};
int main()
{
const char str[] = " aaa bbb ";
// auto find_first_not_of = [&ch](std::string const& str) -> bool
// {
// return !str.find(ch);
// };
auto f = std::find_if(std::cbegin(str), std::cend(str), find_first_not_of(" \t\n\r\f\v"));
if (f != std::cend(str)) {
std::cout << std::distance(std::cbegin(str), f) << std::endl;
}
}
