Date: Tue, 6 May 2025 18:05:04 -0500
On Fri, 25 Apr 2025 at 18:58, Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
wrote:
A quick Google search for "is_structural wg21" turns up:
<snip/>
Anyway, yeah, there's tons of history here; but I'm afraid I don't remember
(or never knew) what all the history *is*.
Thanks for the dive. P3380 specifically looks like it contains what I'm
looking for.
Suppose I know that `T` is structural. Does that mean that I can write
`MyTemplate<T{}>`? No, of course not: `T` might not have a constexpr
default constructor.
<snip/>
Yes I see what you mean, not every possible value in a structural type is
usable as an NTTP. I would agree in saying that this trait has limited
usability, but I wouldn't say that it's useless. If I'm writing a type that
I need to be usable as an NTTP, I would rather `static_assert` this
property with a trait instead of having the compilation fail by writing an
invalid template. But I'm willing to accept that this preference isn't
shared, especially to introduce a new standard trait just for this purpose.
On Sat, 26 Apr 2025 at 02:17, Lénárd Szolnoki <cpp_at_[hidden]>
wrote:
You can write []<T>(){} exactly when T is structural. This is not
SFINAE-friendly. I do agree that the trait probably has limited usability.
Thanks for this lambda! I was racking my brain for the proper way to write
this trait, and this seems to do the trick. I had been trying things much
more complicated than this. This is nice and simple, assuming it actually
works in all cases.
```
template <class T>
concept structural = requires { []<T>(){}; };
template <class T>
constexpr bool is_structural_v = structural<T>;
```
Braden
wrote:
A quick Google search for "is_structural wg21" turns up:
<snip/>
Anyway, yeah, there's tons of history here; but I'm afraid I don't remember
(or never knew) what all the history *is*.
Thanks for the dive. P3380 specifically looks like it contains what I'm
looking for.
Suppose I know that `T` is structural. Does that mean that I can write
`MyTemplate<T{}>`? No, of course not: `T` might not have a constexpr
default constructor.
<snip/>
Yes I see what you mean, not every possible value in a structural type is
usable as an NTTP. I would agree in saying that this trait has limited
usability, but I wouldn't say that it's useless. If I'm writing a type that
I need to be usable as an NTTP, I would rather `static_assert` this
property with a trait instead of having the compilation fail by writing an
invalid template. But I'm willing to accept that this preference isn't
shared, especially to introduce a new standard trait just for this purpose.
On Sat, 26 Apr 2025 at 02:17, Lénárd Szolnoki <cpp_at_[hidden]>
wrote:
You can write []<T>(){} exactly when T is structural. This is not
SFINAE-friendly. I do agree that the trait probably has limited usability.
Thanks for this lambda! I was racking my brain for the proper way to write
this trait, and this seems to do the trick. I had been trying things much
more complicated than this. This is nice and simple, assuming it actually
works in all cases.
```
template <class T>
concept structural = requires { []<T>(){}; };
template <class T>
constexpr bool is_structural_v = structural<T>;
```
Braden
Received on 2025-05-06 23:05:15