In our unit tests, we have several lines, for example:
And indeed, if I uncomment this code, it fails in LexicalCast with static_assert:
static_assert(!std::is_pointer<ToType>::value, "Cannot return pointers from a LexicalCast");
Since in this case it would not be clear who owns the memory.
So, my question is to use any advanced features of C ++ (I was thinking about SFINAE mostly, but not very good at it), can I check if something is compiled due to static_assert in the called function? I do not mind detection at runtime or compile time, and also does not support macros, etc., since these are tests.
EDIT: e.g. I want something like
ASSERT_DOESNT_COMPILE(::Utils::LexicalCast<const char*>(5));
source
share