Looking at this again, I believe there's a bug here:

```c++
memcpy(&val, ptr, sizeof(T));
if (non_native_endian)
  swizzle(reinterpret_cast<char*>(&val), sizeof(T));
```

You're copying val to *ptr then swizzling val but I suspect that it should be the other way around.

There's also the issue of the return value. Returning the swizzled value results in bogus values (usually) but you might also hit upon signalling NaNs, e.g. swizzling a float where `*(uint32_t*)&val & 0x7fb0 == 0x7fb0`.

I'd just return Undefined(), I believe that's what the current implementation does.