Skip to content

compile error on requires to_view #220

Description

@zhuoqiang

I want to check if rfl::to_view() can be applied to a variable of type T, but the following code fails to compile:

template<class T>
void FailedToCompile(T const& t) {
    if constexpr (requires { rfl::to_view(t); }) {
    }
}

int main() {
    std::string s = "hello";
    FailedToCompile(s);
}

As a workaround, I have to use std::is_aggregate_v<T> for the check instead.

Would it be possible to add a concept constraint requiring rfl::to_view to only be applicable when T satisfies std::is_aggregate_v<T>? That way, the if constexpr (requires { rfl::to_view(t); }) condition would work as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions