template <class T> struct alignment_of;
1
template<class T> struct alignment_of : integral_constant <size_t,alignof(T)> {};
123456789101112
// alignment_of example #include <iostream> #include <type_traits> int main() { std::cout << "alignment_of:" << std::endl; std::cout << "char: " << std::alignment_of<char>::value << std::endl; std::cout << "int: " << std::alignment_of<int>::value << std::endl; std::cout << "int[20]: " << std::alignment_of<int[20]>::value << std::endl; std::cout << "long long int: " << std::alignment_of<long long int>::value << std::endl; return 0; }
alignment_of char: 1 int: 4 int[20]: 4 long long int: 8