I know the way of non meta programing to decide a PC is little endian or not.
eg:
#include <iostream>
#include <stdint.h>
union A {
uint16_t v;
char c[2];
};
int main(void) {
A a;
a.v = 0x0102;
std::cout << (a.c[0] == 0x01 ? "big endian" : "little endian") << std::endl;
return 0;
}
But, it’s expensive in run time, isn’t it?
So, is there a way to decide a PC is little endian or not by meta programing?
Thanks!
There’s nothing in the language that requires a target computer to be exclusively big-endian or exclusively little-endian. Indeed, some architectures allow endianness selection by the software at run time. Some even allow per-page endianness selection.
A template metaprogram cannot possibly know anything about this stuff.