C++ Logo

std-discussion

Advanced search

Re: static_error proposal?

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 13 Sep 2019 21:56:32 +0300
On Fri, 13 Sep 2019 at 21:53, Aarón Bueno Villares via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Would it be worthy to add a thing like that to C++?
>
> template<class...>
> inline constexpr bool static_error() { return false; }
>
> It would allow to have a explicitly named tool to force compilations errors within partial specializations or function overloads that should never be instantiated by the user. Example:
>
> template<class T>
> struct something;
>
> template<class T>
> struct something<some_invalid_type_dependant_on_T>
> {
> static_assert(static_error<T>(), "You shall not used that type on this."
> " Use bla bla instead.");
> };
>
> That way you force that specialization to only generate a compiler error when it is instantiated and has passed any sfinae filter since `static_error` depends on a template parameter. Although the best approach would be in my opinion to use "keyword" `static_error` instead of `static_assert` for situations where you always when the specialization to fail.
>
> I won't be surprised if there's some proposal over there similar to this already.

See http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0596r0.html

Received on 2019-09-13 13:58:51