?

Log in

No account? Create an account
Cellular, modular, interactive-odular -- Day [entries|friends|calendar]
some1

Профиль Cellular, modular, interactive-odular

последние | архив | лента друзей | избранное |
[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

FP in C++ [23 Nov 2004|03:29pm]
template<class T, class U>
struct TList
{
    typedef T Head;
    typedef U Tail;
};

class NullType {};

typedef TList<char, TList<short, TList<int,
    TList<long, NullType> > > > SignedIntTypes;

template<class TList> struct Length;

template<>
struct Length<NullType>
{
    enum { value = 0 };
};

template<class T, class U>
struct Length<TList<T, U> >
{
    enum { value = 1 + Length<U>::value };
};

template<class TList, class T> struct IndexOf;

template<class T>
struct IndexOf<NullType, T>
{
    enum { value = -1 };
};

template<class U, class T>
struct IndexOf<TList<T, U>, T>
{
    enum { value = 0 };
};

template<class U, class V, class T>
struct IndexOf<TList<U, V>, T>
{
private:
    enum { temp = IndexOf<V, T>::value };
public:
    enum { value = temp!=-1 ? temp+1 : -1 };
};
Ссылка 4 перфокарт(s)| Доложить

navigation
[ viewing | November 23rd, 2004 ]
[ go | previous day|next day ]