Skip to content

iris::recursive_wrapper should provide std::formatter specialization #37

@saki7

Description

@saki7

Currently, iris::rvariant<iris::recursive_wrapper<T>> does provide std::formatter specialization. It is possible solely because iris::recursive_wrapper<T> is handled as a special case by rvariant's specification.

However, the plain iris::recursive_wrapper<T> cannot be formatted. This was initially considered acceptable because the original std::indirect<T> does not provide formatter specialization. I think this inconsistency is somewhat observable in application code and should be addressed.

int main()
{
    iris::rvariant<int, iris::recursive_wrapper<std::string>> var;
    std::println("var is {}", var); // ok because `rvariant`'s spec explicitly allows this for convenience

    var.visit(iris::overloaded{
        [](int const& val) { std::println("value is {}", val); },
        [](auto const& unhandled_alt) {
            std::println("unhandled alternative: {}", unhandled_alt); // compile error *by design*, but... why?
            std::println("unhandled alternative: {}", var); // ok...... but ugly workaround
        },
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions