C++ Logo

std-discussion

Advanced search

static_error proposal?

From: Aarón Bueno Villares <abv150ci_at_[hidden]>
Date: Fri, 13 Sep 2019 20:52:57 +0200
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.

Best regards,
Aarón.

Received on 2019-09-13 13:55:41