If your purpose is to prevent only one or two types, I believe the current static assert works just fine as you can list the not allowed ones. I think you should change your example message to not say int_32 is not allowed to something more generic 
-- 
  Henry Miller
  hank@millerfarm.com



On Fri, Jun 18, 2021, at 02:26, David Braun via Std-Proposals wrote:

Yes, the part of my code between the two if-statements marked with /*…*/  was meant to imply that.  

 

Another use case would be if you had a function that could take an array or vector of any arithmetic type, but you needed to do something totally different for each type such as processing with AVX2 Intrinsics.

 

However you want to prevent the user of your code from passing a specific type such as one that dose not work with AVX2 such as long double or Intel’s _Quad.

 

Another use case is using if-constexpr to replace macros and preventing the user of your code from passing an invalid macro.

 

Something like this:

 

uint16_t option1 = 1;

uint16_t option2 = 2;

 

template<uint16_t opt>

void myFunc()

{

        if constexpr(opt == option1)

        {

                //Compile option 1

}//End if

else if(opt == option2)

{

        //Compile option 2

}//End if

else

{

        static_failure (“Compile Error! You passed an invalid macro option!”);

}//End else

}//End myFunc

 

You could use static_assert for a simple example like this but imagine a function with 20 MACRO options (they exist), that would be really annoying to have to type blocks of ORs all through a single static_assert and there’d be high chances of making a mistake. I think this design would be a little nicer and cleaner.

 

These are just a few examples. I’m sure there are other use cases. The idea is to be able to place static_failure(“”); anywhere in your code you want to trigger a compile-time error.

 

 

 

David Aaron Braun

519-680-9822

226-236-4898

da.braun1@hotmail.com

 

From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> On Behalf Of chuanqi.xcq via Std-Proposals
Sent: Thursday, June 17, 2021 10:11 PM
To: std-proposals <std-proposals@lists.isocpp.org>
Cc: chuanqi.xcq <yedeng.yd@linux.alibaba.com>
Subject: Re: [std-proposals] Static Failure - Custom Compile-Time Errors

 

Hi David,

 

For the motivation example, it looks same for me to:

```

template<typename T> requires std::is_integral<T>

void my_func(T param) {

static_assert(std::is_same<T, uint8_t>() || std::is_same<T,int64_t>()  ,”Compile Error! You passed an

int32_t into my_func !”);

}

```

 

It looks fine to me. So is the main motivation for static_failure  for the situation in which the list of `if constexpr` is extrmely long?

 

Thanks,

Chuanqi

 

------------------------------------------------------------------

From:David Braun via Std-Proposals <std-proposals@lists.isocpp.org>

Send Time:2021618(星期五) 09:59

To:std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>

Cc:David Braun <da.braun1@hotmail.com>

Subject:[std-proposals] Static Failure - Custom Compile-Time Errors

 

From: David Braun
Sent: Thursday, June 17, 2021 12:29 AM
Subject: C++ 23 Language Proposal for new type of static assertion

 

Here is my proposal for C++ 23.

Thank You!

 

David Aaron Braun

519-680-9822

226-236-4898

da.braun1@hotmail.com

 

 

-- 
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals