[/ Copyright 2007 John Maddock. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). ] [section:alignment_of alignment_of] template struct alignment_of : public __integral_constant {}; __inherit Class template `alignment_of` inherits from `__integral_constant`, where `ALIGNOF(T)` is the alignment of type T. ['Note: strictly speaking you should only rely on the value of `ALIGNOF(T)` being a multiple of the true alignment of T, although in practice it does compute the correct value in all the cases we know about.] __header ` #include ` or ` #include ` __examples [:`alignment_of` inherits from `__integral_constant`.] [:`alignment_of::type` is the type `__integral_constant`.] [:`alignment_of::value` is an integral constant expression with value `ALIGNOF(double)`.] [:`alignment_of::value_type` is the type `std::size_t`.] [important Visual C++ users should note that MSVC has varying definitions of "alignment". For example consider the following code: `` typedef long long align_t; assert(boost::alignment_of::value % 8 == 0); align_t a; assert(((std::uintptr_t)&a % 8) == 0); char c = 0; align_t a1; assert(((std::uintptr_t)&a1 % 8) == 0); `` In this code, even though `boost::alignment_of` reports that `align_t` has 8-byte alignment, the final assert will fail for a 32-bit build because `a1` is not aligned on an 8 byte boundary. Note that had we used the MSVC intrinsic `__alignof` in place of `boost::alignment_of` we would still get the same result. In fact for MSVC alignment requirements (and promises) only really apply to dynamic storage, and not the stack. ] [endsect]