<p>I have some low level serialization code that is templated, and I need to know the system's endianness at compiletime obviously (because the templates specializes based on the system's endianness).  </p>

<p>Right now I have a header with some platform defines, but I'd rather have someway to make assertions about endianness with some templated test (like a static_assert or boost_if). Reason being my code will need to be compiled and ran on a wide range of machines, of many specialized vendor, and probably devices that don't exist in 2008, so I can't really guess what might need to go into that header years down the road. And since the code-base has an expected lifetime of about 10 years. So I can't follow the code for-ever.</p>

<p>Hopefully this makes my situation clear.</p>

<p>So does anyone know of a compile-time test that can determine endianness, without relying on vendor specific defines?</p>

Hmm, that's an interesting Question. My bet is that this is not possible. I think you have to continue using macros, and go with
```
BOOST_STATIC_ASSERT(!BIG_ENDIAN);
```
, or
```
static_assert
```
in c++0x. The reason i think this is because the endian'nes is a property if your execution environment. However, static_assert is considered at compile time.
I suggest you look into the code of the new
GNU gold
ELF linker. Ian Lance Taylor, its author, used templates to select the right endianness at compile time, to ensure optimal performance at run time. He explicitely instantiates all possible endians, so that he still has separate compilation (not all templates in headers) of the template definition and declaration. His code is excellent.