Skip to content

Constraints vs static_assert #2

@brevzin

Description

@brevzin

(This is not necessarily an issue).

The way that the various type classes are implemented all look basically like this:

template <typename T1, typename T2>
static std::optional<M> append(T1&& left, T2&& right) {
    static_assert(std::is_same_v<std::remove_cvref_t<T1>, std::optional<M>>, "Argument type should be the same as monoid");
    static_assert(std::is_same_v<std::remove_cvref_t<T2>, std::optional<M>>, "Argument type should be the same as monoid");

Is there a reason you chose unconstrained arguments with a static_assert, as opposed to an implementation strategy like:

template <DecaysTo<std::optional<M>> T1, DecaysTo<std::optional<M>> T2>
static std::optional<M> append(T1&& left, T2&& right) {
    // no static_asserts
}

The former might give you better diagnostics for direct invocations, the latter lets you "bubble up" the constraint to catch it earlier in the call stack.

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