Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions include/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@

auto check_errors(ArgumentImpl const & /* impl */, std::string_view /* value */, std::ranges::view auto /* tokens */) const -> void
{
// skip
}

auto assign_non_present_value(ArgumentImpl const & /* impl */, std::any & value) const -> void
Expand All @@ -831,6 +832,7 @@

auto check_errors(ArgumentImpl const & /* impl */, std::string_view /* value */, std::ranges::view auto /* tokens */) const -> void
{
// skip
}

auto assign_non_present_value(ArgumentImpl const & /* impl */, std::any & value) const -> void
Expand Down Expand Up @@ -1467,11 +1469,6 @@
});
}

private:
ArgumentImpl m_impl;
std::any m_value;
bool m_present = false;

public:
explicit OptionalArgument(Options options)
: m_impl(std::move(options))
Expand Down Expand Up @@ -1518,9 +1515,9 @@

auto get_dest_name() const -> std::string override
{
if (!m_impl.get_dest().empty())
if (auto const & dest = m_impl.get_dest(); !dest.empty())
{
return m_impl.get_dest();
return dest;
}

auto dest = get_name_for_dest();
Expand All @@ -1532,9 +1529,9 @@

auto get_metavar_name() const -> std::string override
{
if (!m_impl.get_metavar().empty())
if (auto const & metavar = m_impl.get_metavar(); !metavar.empty())
{
return m_impl.get_metavar();
return metavar;
}

auto metavar = get_dest_name();
Expand Down Expand Up @@ -1638,6 +1635,11 @@
{
return m_impl.get_nargs_option();
}

private:
ArgumentImpl m_impl;
std::any m_value;
bool m_present = false;
};

using ArgumentVariant = std::variant<PositionalArgument, OptionalArgument>;
Expand Down Expand Up @@ -1918,11 +1920,11 @@

if (is_positional())
{
m_arguments.push_back(PositionalArgument(std::move(m_options)));
m_arguments.emplace_back(PositionalArgument(std::move(m_options)));

Check failure on line 1923 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not throw uncaught exceptions in a destructor.

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrkwltnyBsur7zwEzai&open=AZrkwltnyBsur7zwEzai&pullRequest=184
}
else
{
m_arguments.push_back(OptionalArgument(std::move(m_options)));
m_arguments.emplace_back(OptionalArgument(std::move(m_options)));

Check failure on line 1927 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not throw uncaught exceptions in a destructor.

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrkwltnyBsur7zwEzaj&open=AZrkwltnyBsur7zwEzaj&pullRequest=184
}
}

Expand Down