use std::regex_token_iterator instead of boost tokenized

This commit is contained in:
Michael Krasnyk 2017-03-29 08:31:24 +02:00 committed by Patrick Niklaus
parent ac6f07a744
commit 7a1a209168

View File

@ -12,11 +12,11 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/range/adaptor/tokenized.hpp>
#include <boost/range/adaptor/transformed.hpp> #include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <iostream> #include <iostream>
#include <iterator>
#include <regex>
using namespace osrm; using namespace osrm;
@ -34,9 +34,8 @@ struct MaxCellSizesArgument
std::ostream &operator<<(std::ostream &os, const MaxCellSizesArgument &arg) std::ostream &operator<<(std::ostream &os, const MaxCellSizesArgument &arg)
{ {
return os << boost::algorithm::join( auto to_string = [](std::size_t x) { return std::to_string(x); };
arg.value | boost::adaptors::transformed([](auto x) { return std::to_string(x); }), return os << boost::algorithm::join(arg.value | boost::adaptors::transformed(to_string), ",");
",");
} }
void validate(boost::any &v, const std::vector<std::string> &values, MaxCellSizesArgument *, int) void validate(boost::any &v, const std::vector<std::string> &values, MaxCellSizesArgument *, int)
@ -50,8 +49,12 @@ void validate(boost::any &v, const std::vector<std::string> &values, MaxCellSize
// one string, it's an error, and exception will be thrown. // one string, it's an error, and exception will be thrown.
const std::string &s = validators::get_single_string(values); const std::string &s = validators::get_single_string(values);
std::regex re(",");
std::vector<size_t> output; std::vector<size_t> output;
boost::copy(s | tokenized(boost::regex("[^,]+")) | transformed([](const auto &x) { std::transform(std::sregex_token_iterator(s.begin(), s.end(), re, -1),
std::sregex_token_iterator(),
std::back_inserter(output),
[](const auto &x) {
try try
{ {
return boost::lexical_cast<std::size_t>(x); return boost::lexical_cast<std::size_t>(x);
@ -60,8 +63,7 @@ void validate(boost::any &v, const std::vector<std::string> &values, MaxCellSize
{ {
throw validation_error(validation_error::invalid_option_value); throw validation_error(validation_error::invalid_option_value);
} }
}), });
std::back_inserter(output));
v = boost::any(MaxCellSizesArgument{output}); v = boost::any(MaxCellSizesArgument{output});
} }