Fix Argument bool bit fields

The intent of ": 1" is to use individual bits to store the bool state of
these class values. Because true != 0, this worked. But it was likely to
bite someone sometime. (My bad: 0fe17e22f6.)

This commit also adds m_accepts_optional_like_value to the bit field and
sets the default false value in the constructor.

Because we cannot set a default value during declaration (until C++20).
make sure future coders know to set the preferred default in the
constructor.

Closes #213

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This commit is contained in:
Sean Robinson 2023-01-05 12:08:03 -07:00
parent 04ac1fe366
commit d845381028

View File

@ -376,7 +376,8 @@ class Argument {
explicit Argument(std::string_view prefix_chars, explicit Argument(std::string_view prefix_chars,
std::array<std::string_view, N> &&a, std::array<std::string_view, N> &&a,
std::index_sequence<I...> /*unused*/) std::index_sequence<I...> /*unused*/)
: m_is_optional((is_optional(a[I], prefix_chars) || ...)), : m_accepts_optional_like_value(false),
m_is_optional((is_optional(a[I], prefix_chars) || ...)),
m_is_required(false), m_is_repeatable(false), m_is_used(false), m_is_required(false), m_is_repeatable(false), m_is_used(false),
m_prefix_chars(prefix_chars) { m_prefix_chars(prefix_chars) {
((void)m_names.emplace_back(a[I]), ...); ((void)m_names.emplace_back(a[I]), ...);
@ -1033,11 +1034,12 @@ private:
[](const std::string &value) { return value; }}; [](const std::string &value) { return value; }};
std::vector<std::any> m_values; std::vector<std::any> m_values;
NArgsRange m_num_args_range{1, 1}; NArgsRange m_num_args_range{1, 1};
bool m_accepts_optional_like_value = false; // Bit field of bool values. Set default value in ctor.
bool m_is_optional : true; bool m_accepts_optional_like_value : 1;
bool m_is_required : true; bool m_is_optional : 1;
bool m_is_repeatable : true; bool m_is_required : 1;
bool m_is_used : true; // True if the optional argument is used by user bool m_is_repeatable : 1;
bool m_is_used : 1;
std::string_view m_prefix_chars; // ArgumentParser has the prefix_chars std::string_view m_prefix_chars; // ArgumentParser has the prefix_chars
}; };