cmdopt2/args: create a parseable
trait
This commit is contained in:
parent
179f016fa1
commit
11dc485c88
@ -29,6 +29,10 @@ namespace cruft::cmdopt2 {
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
concept parseable = std::is_arithmetic_v<T>;
|
||||
|
||||
|
||||
template <typename BaseT>
|
||||
struct ops_t : argument_t {
|
||||
template <typename ValueT>
|
||||
@ -39,7 +43,7 @@ namespace cruft::cmdopt2 {
|
||||
bind (ValueT &ref)
|
||||
{
|
||||
CHECK (!acceptor1);
|
||||
if constexpr (cruft::concepts::stringy<ValueT>) {
|
||||
if constexpr (parseable<ValueT>) {
|
||||
acceptor1 = [&ref] (std::string_view str) { ref = str; };
|
||||
} else {
|
||||
acceptor1 = [&ref] (std::string_view str) { ref = parse::from_string<ValueT> (str); };
|
||||
@ -53,7 +57,7 @@ namespace cruft::cmdopt2 {
|
||||
{
|
||||
CHECK (!acceptor1);
|
||||
|
||||
if constexpr (std::is_same_v<ValueT, std::string>) {
|
||||
if constexpr (parseable<ValueT>) {
|
||||
acceptor1 = [&ref] (std::string_view str) { ref = str; };
|
||||
} else {
|
||||
acceptor1 = [&ref] (std::string_view str) { ref = parse::from_string<ValueT> (str); };
|
||||
|
Loading…
Reference in New Issue
Block a user