Date: Sun, 15 Sep 2024 10:36:15 +0200
Hi!
Another thing I found that I'd like in concepts is the notion that e.g. a
function related to a type can or shall be evaluated at compile time. For
example, this:
```c++
template <typename T>
concept has_foo = requires() {
{ T::foo() /*consteval*/ } -> is_foo_like;
};
```
This is because I may want to use the result of `foo` to distinguish what
kind of reflections I should be allowed to use on `T`, and what should be
considered a compile error. I.e. I want to use it as:
```c++
void bar(has_foo auto const& my_t) {
if constexpr(T::foo(/*possible use of consteval arguments as well*/) ==
something_else) {
do_foo_only_stuff(my_t);
}
}
```
// Robin
Another thing I found that I'd like in concepts is the notion that e.g. a
function related to a type can or shall be evaluated at compile time. For
example, this:
```c++
template <typename T>
concept has_foo = requires() {
{ T::foo() /*consteval*/ } -> is_foo_like;
};
```
This is because I may want to use the result of `foo` to distinguish what
kind of reflections I should be allowed to use on `T`, and what should be
considered a compile error. I.e. I want to use it as:
```c++
void bar(has_foo auto const& my_t) {
if constexpr(T::foo(/*possible use of consteval arguments as well*/) ==
something_else) {
do_foo_only_stuff(my_t);
}
}
```
// Robin
Received on 2024-09-15 08:38:28