Skip to content

Commit

Permalink
Expanded the functionality of the parameters helper - you can now spe…
Browse files Browse the repository at this point in the history
…cify

default values for which the types can be automatically inferred if
needed. This means the "values" vector size can be smaller than the
parameter pack.

Example:
```
const auto [a,b,c,d] = emergent::parameters::get(values, 5, "hi"s, 3.14, true );
```
  • Loading branch information
parnham committed Sep 4, 2024
1 parent bcdd8d6 commit 3945904
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/emergent/Clap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ namespace emergent

return create_tuple<Types...>(std::index_sequence_for<Types...> {}, values);
}


template <typename T> T retrieve(const std::vector<std::string> &values, const size_t index, const T &def)
{
return index < values.size() ? transform<T>(values[index]) : def;
}

template <typename... Types, std::size_t... Is> auto create_tuple(std::index_sequence<Is...>, const std::vector<std::string> &values, Types... defaults)
{
return std::make_tuple(retrieve<Types>(values, Is, defaults)...);
}

template <typename... Types> std::tuple<Types...> get(const std::vector<string> &values, Types... defaults)
{
return create_tuple<Types...>(std::index_sequence_for<Types...> {}, values, defaults...);
}
}


// A command-line argument parser.
class Clap
{
Expand Down

0 comments on commit 3945904

Please sign in to comment.