Public Member Functions | List of all members
Options::Auto< T, Label > Class Template Reference

A class indicating that a parsed value can be automatically computed instead of specified. More...

#include <Auto.hpp>

Public Member Functions

 Auto (T value) noexcept
 

Detailed Description

template<typename T, typename Label = AutoLabel::Auto>
class Options::Auto< T, Label >

A class indicating that a parsed value can be automatically computed instead of specified.

When an Auto<T> is parsed from an input file, the value may be specified either as the AutoLabel (defaults to "Auto") or as a value of type T. When this class is passed to the constructor of the class taking it as an option, it can be implicitly converted to a std::optional<U>, for any type U implicitly creatable from a T.

class ExampleClass {
public:
ExampleClass() = default;
struct AutoArg {
using type = Options::Auto<int>;
static type suggested_value() noexcept { return {}; }
static constexpr Options::String help =
"Integer that can be automatically chosen";
};
struct OptionalArg {
static constexpr Options::String help = "Optional parameter";
};
static constexpr Options::String help =
"A class that can automatically choose an argument";
using options = tmpl::list<AutoArg, OptionalArg>;
explicit ExampleClass(std::optional<int> auto_arg,
std::optional<double> opt_arg) noexcept
: value(auto_arg ? *auto_arg : -12), optional_value(opt_arg) {}
int value{};
std::optional<double> optional_value{};
};
const auto example1 = TestHelpers::test_creation<ExampleClass>(
"AutoArg: 7\n"
"OptionalArg: 10.");
CHECK(example1.value == 7);
CHECK(example1.optional_value == 10.);
const auto example2 = TestHelpers::test_creation<ExampleClass>(
"AutoArg: Auto\n"
"OptionalArg: None");
CHECK(example2.value == -12);
CHECK(example2.optional_value == std::nullopt);

The documentation for this class was generated from the following file:
Options::Auto
A class indicating that a parsed value can be automatically computed instead of specified.
Definition: Auto.hpp:36
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
std::optional