Date: Fri, 18 Jun 2021 17:17:59 +0800
> Whole problem here is that `static_assert` has a design goal to be
> eager in evaluation of its condition. And changing this will reduce
> its usefulness in that case.
Out of curiousty, in what situation, changing this would reduce its usefulness?
> Here are some data to consider:
>
> template<bool B>
> void func() {
> if constexpr (B) {
> static_assert(false, "message");
> }
> }
>
> and
>
> template<bool B>
> void func;
>
> template<>
> void func<true>() {
> static_assert(false, "message");
> }
>
> template<>
> void func<false>() {}
Yeah, this is an example. And from my point of view, changing this would make
the power of static_assert get weaker in `if constexpr`. But it is OK for me,
from my experience for using static_assert, it seems OK to assert evaluate lazily (after instantiation).
I am curious about if there is any realistic example tell the down side for lazily evaluate assert.
Thanks,
Chuanqi
------------------------------------------------------------------
From:Jefferson Carpenter via Std-Proposals <std-proposals_at_[hidden]>
Send Time:2021年6月18日(星期五) 16:09
To:std-proposals <std-proposals_at_[hidden]>
Cc:Jefferson Carpenter <jeffersoncarpenter2_at_[hidden]>
Subject:Re: [std-proposals] Static Failure - Custom Compile-Time Errors
On 6/18/2021 7:49 AM, chuanqi.xcq via Std-Proposals wrote:
> Yeah, another question is that can we use 'static_assert(false, "string");' to replace the use case? I understand the current document and implementation wouldn't work.
> But I mean, what if to change the semantics for static_assert to make `static_assert(false, "")` work for the use case you mentioned? It looks not bad to me, too.
Here are some data to consider:
template<bool B>
void func() {
if constexpr (B) {
static_assert(false, "message");
}
}
and
template<bool B>
void func;
template<>
void func<true>() {
static_assert(false, "message");
}
template<>
void func<false>() {}
both fail to compile. So currently static_assert behaves similarly
whether it is used with template specializations, or with `if constexpr`
statements. (Even if the code in question is never instantiated)
> eager in evaluation of its condition. And changing this will reduce
> its usefulness in that case.
Out of curiousty, in what situation, changing this would reduce its usefulness?
> Here are some data to consider:
>
> template<bool B>
> void func() {
> if constexpr (B) {
> static_assert(false, "message");
> }
> }
>
> and
>
> template<bool B>
> void func;
>
> template<>
> void func<true>() {
> static_assert(false, "message");
> }
>
> template<>
> void func<false>() {}
Yeah, this is an example. And from my point of view, changing this would make
the power of static_assert get weaker in `if constexpr`. But it is OK for me,
from my experience for using static_assert, it seems OK to assert evaluate lazily (after instantiation).
I am curious about if there is any realistic example tell the down side for lazily evaluate assert.
Thanks,
Chuanqi
------------------------------------------------------------------
From:Jefferson Carpenter via Std-Proposals <std-proposals_at_[hidden]>
Send Time:2021年6月18日(星期五) 16:09
To:std-proposals <std-proposals_at_[hidden]>
Cc:Jefferson Carpenter <jeffersoncarpenter2_at_[hidden]>
Subject:Re: [std-proposals] Static Failure - Custom Compile-Time Errors
On 6/18/2021 7:49 AM, chuanqi.xcq via Std-Proposals wrote:
> Yeah, another question is that can we use 'static_assert(false, "string");' to replace the use case? I understand the current document and implementation wouldn't work.
> But I mean, what if to change the semantics for static_assert to make `static_assert(false, "")` work for the use case you mentioned? It looks not bad to me, too.
Here are some data to consider:
template<bool B>
void func() {
if constexpr (B) {
static_assert(false, "message");
}
}
and
template<bool B>
void func;
template<>
void func<true>() {
static_assert(false, "message");
}
template<>
void func<false>() {}
both fail to compile. So currently static_assert behaves similarly
whether it is used with template specializations, or with `if constexpr`
statements. (Even if the code in question is never instantiated)
-- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2021-06-18 04:18:04