Skip to content

Help with detecting if optional is valid #230

@shyun3

Description

@shyun3

Hello, I'm trying to do something like the following in order to select the most compact optional available:

template <typename T>
using MinOptional = std::conditional_t<requires { stdx::optional<T>{}; },
                                       stdx::optional<T>, std::optional<T>>;

// or

template <typename T>
using MinOptional = std::conditional_t<requires {
    stdx::tombstone_traits<T>{}();
}, stdx::optional<T>, std::optional<T>>;

The idea was to select stdx::optional if tombstone_traits has been specialized and if not, select std::optional. However, my attempt runs into a static assert for types that do not have the tombstone traits specialized. Is there currently a way to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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