Boost.StringAlgo splitにラムダを渡す
文字列を指定されたトークンで分割するboost::algorithm::split()関数には通常、is_any_of関数オブジェクトでトークンを指定しますが、ラムダ式も渡せます。
#include <iostream> #include <boost/algorithm/string/split.hpp> #include <string> #include <vector> int main() { std::vector<std::string> v; std::string s = "123,456.789"; boost::algorithm::split(v, s, [](char c) { return c == ',' || c == '.'; }); for (const std::string& x : v) { std::cout << x << std::endl; } }
123 456 789
参照:
Function template split - Boost String Algo Library