Skip to content

Extracting scanned value is cumbersome. #140

Description

@hellokartikey

The current API for extracting the scanned result is very cumbersome (IMO).

Sometimes it is better to return a fallback value when scan fails.

  ...
  auto number = scn::input<int>("{}").value_or(42);
  ...

The current way of achieving this is unnecessarily long.

  ...
  int number; // Have an uninitialized variable
  if (auto result = scn::input<int>("{}"); result) {
    number = result->value();
  else {
    number = 42;
  }
  ...

or

  ...
  int number = scn::input<int>("{}").value().value(); // Could throw and no fallback value
  ...

Having a scn::scan_result inside a std::expected can be somewhat inconvenient. Maybe having a single result type would be better?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions