namespace NAlignOf
{
    template <class TType>
    struct TSizeIncrement: TType
    {
        char Increment;
    };

    template <class TType, unsigned Start, bool Stop>
    struct TIncreaseSizeImpl: TIncreaseSizeImpl<TSizeIncrement<TType>, Start,
        sizeof(TSizeIncrement<TType>) != Start>
    {
    };

    template <class TType, unsigned Start>
    struct TIncreaseSizeImpl<TType, Start, true>
    {
        typedef TType TType_;
    };

    template <class TType>
    struct TIncreaseSize: TIncreaseSizeImpl<TType, sizeof(TType), false>
    {
    };

    template <class TType>
    struct TAlignOf
    {
        typedef typename TIncreaseSize<TType>::TType_ TIncreased_;
        static const unsigned Value_ =
            sizeof(typename TIncreaseSize<TIncreased_>::TType_)
            - sizeof(TIncreased_);
    };
}

#include <iostream>

struct S0
{
    char c;
};

struct S1
{
    char c;
    short s;
};

struct S2
{
    char c;
    int i;
    char c2;
};

struct S3
{
    char c;
    char c2;
    int i;
};

struct S4
{
    double d;
};

struct S5
{
    char c;
    long double d;
}__attribute__((packed));

int main()
{
    std::cout << NAlignOf::TAlignOf<S0>::Value_ << std::endl;
    std::cout << NAlignOf::TAlignOf<S1>::Value_ << std::endl;
    std::cout << NAlignOf::TAlignOf<S2>::Value_ << std::endl;
    std::cout << NAlignOf::TAlignOf<S3>::Value_ << std::endl;
    std::cout << NAlignOf::TAlignOf<S4>::Value_ << std::endl;
    std::cout << NAlignOf::TAlignOf<S5>::Value_ << std::endl;
}

