Skip to content

Commit

Permalink
argparse update
Browse files Browse the repository at this point in the history
- fix argument::required template deduction
  • Loading branch information
jrmadsen committed Jun 25, 2024
1 parent 693746c commit 227559a
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions source/timemory/utility/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,31 @@ struct argument_parser
return *this;
}

argument& required(bool req, std::string _msg = "")
template <typename Tp>
argument& required(std::initializer_list<Tp>&& _v)
{
container_append(m_requires, std::vector<Tp>{ _v });
return *this;
}

template <typename Tp>
argument& required(Tp&& _v, std::string_view _msg = {})
{
m_required = req;
m_required_info =
(_msg.empty()) ? "" : std::string{ " :: " } + std::move(_msg);
using core_type = concepts::unqualified_type_t<Tp>;
if constexpr(std::is_same<core_type, bool>::value)
{
m_required = _v;
}
else
{
static_assert(helpers::is_initializing_container<core_type>::value,
"Error! Expected a container or initializer_list");
container_append(m_requires, std::forward<Tp>(_v));
}

if(!_msg.empty())
m_required_info += std::string{ " :: " } + std::string{ _msg };

return *this;
}

Expand Down Expand Up @@ -572,22 +592,6 @@ struct argument_parser
return *this;
}

template <typename Tp>
argument& required(std::initializer_list<Tp>&& _v)
{
container_append(m_requires, std::vector<Tp>{ _v });
return *this;
}

template <typename Tp>
argument& required(Tp&& _v)
{
static_assert(helpers::is_initializing_container<Tp>::value,
"Error! Expected a container or initializer_list");
container_append(m_requires, std::forward<Tp>(_v));
return *this;
}

template <typename ActionFuncT>
argument& action(ActionFuncT&& _func)
{
Expand Down

0 comments on commit 227559a

Please sign in to comment.