c++ - How can I confirm an assumption of an automatically inferenced type at compile time? (i.e. static_assert style -
occasionally, i'll assign returned value of function variable of auto type (e.g. auto returnvalue = somefunction();), still clarify/enforce assumptions type of variable - i.e. of type int.
while concepts & type_traits provide powerful static assumption-verifying features, don't enable this:
static_assert( istype( returnvalue, int ) ); //or static_assert( int == typeof( returnvalue ) ); how can this?
you can utilize type traits ie std::is_same here :
static_assert( std::is_same<int, decltype( returnvalue ) >:: value , "error, bad type"); demo here.
c++ c++11 compile-time static-assert
No comments:
Post a Comment