C++ Logo

std-proposals

Advanced search

[std-proposals] Access-level aware concepts

From: Robin Savonen Söderholm <robinsavonensoderholm_at_[hidden]>
Date: Sat, 12 Oct 2024 15:03:34 +0200
Hi!
I can't seem to find any information about how constraints and class access
specifiers could work together. Currently it seems like concepts are always
evaluated from "outside" a class (i.e. only public fields and methods
affect the evaluation of the constraint). E.g. for example:
```c++

#include <concepts>
#include <utility>

class clazz_with_protected_ctor {
protected:
  explicit clazz_with_protected_ctor(int) {}
};

template <typename T>
struct clazz_wrapper: private T {
 template <typename... Ts>
   requires(std::constructible_from<T, Ts&&...>) explicit
clazz_wrapper(Ts&&... args) : T(std::forward<T>(args)...) {}
};

void foo() {
// Generates compile-error since the constraint for the constructor can't
see the protected constructor
auto my_wrapper = clazz_wrapper<clazz_with_protected_ctor>(1);
}
```

I wonder if not the above code should actually be a sensible piece of code
(especially with CRTP-based API:s), and it may be needed that constraints
are evaluated from the context that they are used.

// Robin

Received on 2024-10-12 13:03:50