I have some code where i want to check for (accidental) double pointers in static_assert
#include<type_traits>
int main()
{
using namespace std;
float* arr[10];
float ** pp;
static_assert(!is_pointer<decltype(*arr)>::value, "double pointer detected");
static_assert(!is_pointer<decltype(*pp)>::value, "double pointer detected");
}
I am curious why this compiles, as i was expecting the static_asserts to give an error.
Both of those decltypes resolve to reference types, and therefore neither are pointers, and hence the static assertions pass. These would also pass:
static_assert(std::is_pointer<std::remove_reference_t<decltype(*arr)>>::value);
static_assert(std::is_pointer<std::remove_reference_t<decltype(*pp)>>::value);