Last active
January 1, 2016 19:59
-
-
Save satishgoda/8193974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <type_traits> | |
#include <typeinfo> | |
#include <typeindex> | |
class A { }; | |
class A1 { char c; }; | |
class A2 { char c1; char c2; }; | |
class B { char c; int i; }; | |
class C { char c; int i; double d; }; | |
class D { int i; char c; double d; }; | |
class E { char c[6]; int i; double d; }; | |
class F { char c[6]; int i; }; | |
using namespace std; | |
template<class T> class AlignmentSizeInfo; | |
template <class T> | |
ostream& operator<<(ostream& out, const AlignmentSizeInfo<T>& alignsize) | |
{ | |
out << right | |
<< setw(3) << alignment_of<T>::value << " " | |
<< setw(3) << sizeof(T) << " " | |
<< left << setw(13) << type_index(typeid(T)).name() | |
<< endl; | |
return out; | |
} | |
template <class T> | |
class AlignmentSizeInfo | |
{ | |
public: | |
AlignmentSizeInfo() { | |
cout << *this; | |
} | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
AlignmentSizeInfo<char> asChar; | |
AlignmentSizeInfo<int> asInt; | |
AlignmentSizeInfo<double> asDouble; | |
AlignmentSizeInfo<A> asA; | |
AlignmentSizeInfo<A1> asA1; | |
AlignmentSizeInfo<A2> asA2; | |
AlignmentSizeInfo<B> asB; | |
AlignmentSizeInfo<C> asC; | |
AlignmentSizeInfo<D> asD; | |
AlignmentSizeInfo<E> asE; | |
AlignmentSizeInfo<F> asF; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment