Class ArgVector

Class Documentation

class ArgVector

Represents a set of 0 or more values associated with a given command-line option.

This class allows the internal data to be interpreted as a discrete set of values (std::array) of a given type or as a single value, hopefully making it more intuitive for users. For example…

If an ArgVector v is expected to hold one value of type double, that value can be extracted with auto r = v.as<double>();. This means r will be a double value assigned with the contents of the first element of v.

If an ArgVector v is expected to hold two values of type int, on the other hand, the values can be extracted as a std::array<int, 2> using as<int, 2>(). Using std::array allows structured bindings for the user: auto [a, b] = v.as<int, 2>();

Public Functions

ArgVector() = default

Default is empty (no values)

template<typename T>
inline ArgVector(T &&val)

Construct with a single value.

template<typename T, std::size_t N>
inline std::array<T, N> as() const

Interpret as N values of type T

template<std::size_t N>
inline decltype(auto) as() const

Interpret as N values of type std::string

template<typename T>
inline decltype(auto) as() const

Interpret as single value of type T

inline const std::string &operator()() const

Interpret as single std::string value.

inline const ArgValue &operator[](std::size_t i) const

Get one of the contained ArgValue objects.

inline bool empty() const

Check for existence of values.

inline std::size_t size() const

Get number of ArgValue objects.