22 #ifndef GEARS_OPTPAESE_ACTIONS_HPP
23 #define GEARS_OPTPAESE_ACTIONS_HPP
25 #include "../string/lexical_cast.hpp"
82 T
operator()(
const std::string&,
const std::string& value)
const {
89 bool operator()(
const std::string& key,
const std::string& value)
const {
90 if(value ==
"1" || value ==
"true") {
93 else if(value ==
"0" || value ==
"false") {
97 throw std::runtime_error(
"invalid boolean argument passed to '" + key +
'\'');
145 template<
typename Container,
typename Action = store<
typename Container::value_type>>
147 static_assert(std::is_convertible<decltype(std::declval<Action>()(
"",
"")),
typename Container::value_type>::value,
148 "The action must return a type convertible to the container's value type");
167 Container
operator()(
const std::string& key,
const std::string& value)
const {
169 std::istringstream ss(value);
170 std::insert_iterator<Container> it(result, result.end());
171 for(std::string str; std::getline(ss, str); ) {
172 *it = action(key, str);
189 template<
typename Container>
192 using value_type =
typename Container::value_type;
193 std::function<value_type(const std::string&, const std::string&)> action;
196 template<
typename Action>
197 append(Action action): action(std::move(action)) {}
212 Container
operator()(
const std::string& key,
const std::string& value) {
213 cont.insert(cont.end(), action(key, value));
220 #endif // GEARS_OPTPAESE_ACTIONS_HPP