Search code examples
c++c++20forward-declarationc++-concepts

Why is there no forward declaration in concepts c++?


When I try this example:

template <typename T>
concept only_int = std::same_as<T, int>;

int add_ints(only_int auto&&... args) {
    return (std::forward<decltype(args)>(args) + ... + 0);
}

It works... but when I only declare it like this:

template <typename T>
concept only_int;

...

// defined later on...

It would throw compilation errors.

Is this a missing feature? or it is intended to leave like this?


Solution

  • If you could forward-declare concepts, then you could use them recursively. By preventing forward-declaration, there doesn't have to be an explicit provision in a concept declaration to stop you from using them recursively.