Browse Source

Fix arguments with default values

Sam Jaffe 4 years ago
parent
commit
8c61ba484c
1 changed files with 7 additions and 6 deletions
  1. 7 6
      include/program_args/arguments_impl.hpp

+ 7 - 6
include/program_args/arguments_impl.hpp

@@ -11,15 +11,16 @@ namespace program {
 template <typename Impl>
 template <typename T>
 Arguments<Impl>::Argument::operator T() const {
-  return (*this) ? convert<T>(self->arguments.at(index)) : T();
+  if (!primed()) {
+    return T();
+  } else if (self->arguments.size() > index) {
+    return convert<T>(self->arguments.at(index));
+  }
+  throw IllegalPositionError("No argument provided", index);
 }
 
 template <typename Impl> Arguments<Impl>::Argument::operator bool() const {
-  bool const good = primed();
-  if (good && self->arguments.size() <= index) {
-    throw IllegalPositionError("No argument provided", index);
-  }
-  return good;
+  return primed() && self->arguments.size() > index;
 }
 
 template <typename Impl>