Is there some standard function which takes a piece of code and checks whether it causes an error, returning true if the code is valid but false if the code is invalid?
For example:
int x;
bool a_bool = DoesItCauseAnError(constexpr auto y = x;); // Here a_bool is false, as "constexpr auto y = x;" would cause an error as x is not constexpr
This would be immensely useful and would save us all from all the pain of SFINAE and other weird hacks.
- Is there a standard function which does this?
- If not, why has it not been done already? It would be so useful and seems quite easy to implement.
- If there isn't a standard function, has anybody done a plugin / static tool / compiler specific instruction (preferably gcc or clang) which can do this?