Skip to content

Idea: make it possible to obtain std::partial_ordering from a match #17

Open
@leni536

Description

@leni536

Right now there is an implicit conversion from a match (more explicitly from a captured_content::storage as I can see). I wonder if it was possible to convert a match to std::partial_ordering to obtain more information from a non-match. The semantics of the returned values would be:

  • std::less/std::greater : Not a match and the subject orders lexicographically before/after all possible strings that match the regular expression.
  • std::equivalent : It's a match.
  • std::unordered : All else.

Use case: searching matching strings in a lexicographically ordered collection of strings efficiently. Right now there is no interface for std::map and std::set to allow this, but other maps and sets could offer searching with a partial_ordering predicate.

Some examples for return values:

constexpr auto re = ctre::match<"^abc[0-46-9]+$">;
static_assert(re("abc1"sv).to_partial_ordering() == std::equivalent);
static_assert(re("bac1"sv).to_partial_ordering() == std::greater);
static_assert(re("aaa1"sv).to_partial_ordering() == std::less);
static_assert(re("abc5"sv).to_partial_ordering() == std::unordered);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions