Click here to Skip to main content
15,893,266 members
Articles / Mobile Apps

Tiny Template Library: variant

Rate me:
Please Sign up or sign in to vote.
4.88/5 (14 votes)
23 Feb 20043 min read 84.2K   697   28  
An article on how to implement and use variant<>. Variant is useful for creating heterogeneous containers and much more.
//  macro_params.hpp
//
//  Copyright (c) 2003 Eugene Gladyshev
//
//  Permission to copy, use, modify, sell and distribute this software
//  is granted provided this copyright notice appears in all copies.
//  This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.
//

#ifndef __ttl_macro_params__hpp
#define __ttl_macro_params__hpp

#include "ttl/macro_repeat.hpp"


#define TTL_TPARAM(n,t) typename t##n, 
#define TTL_TPARAM_END(n,t) typename t##n
#define TTL_TPARAM_DEF(n, p) typename T##n = p, 
#define TTL_TPARAM_DEF_END(n, p) typename T##n = p

#define TTL_TPARAMSX(n,t) TTL_REPEAT(n, TTL_TPARAM, TTL_TPARAM_END, t)
#define TTL_TPARAMS(n) TTL_TPARAMSX(n,T)
#define TTL_TPARAMS_DEF(n, def) TTL_REPEAT(n, TTL_TPARAM_DEF, TTL_TPARAM_DEF_END, def)


#define TTL_ARG(n,t) t##n, 
#define TTL_ARG_END(n,t) t##n
#define TTL_ARG_S(n,t) TTL_APPEND(t, TTL_CNTINC_##n),
#define TTL_ARG_S_END(n,t) TTL_APPEND(t, TTL_CNTINC_##n)

#define TTL_ARGS(n) TTL_REPEAT(n, TTL_ARG, TTL_ARG_END, T)
#define TTL_ARGSX(n,p) TTL_REPEAT(n, TTL_ARG, TTL_ARG_END, p)
#define TTL_ARGS_S(n) TTL_REPEAT(n, TTL_ARG_S, TTL_ARG_S_END, T)
#define TTL_ARGS_SX(n,p) TTL_REPEAT(n, TTL_ARG_S, TTL_ARG_S_END, p)

#define TTL_TYPEDEF(n, t) typedef t##n type##n;
#define TTL_TYPEDEF_END(n, t) typedef t##n type##n;
#define TTL_TYPEDEFS(n) TTL_REPEAT(n, TTL_TYPEDEF, TTL_TYPEDEF_END, T)

#define TTL_LIST_ITEM(n, t) t,
#define TTL_LIST_ITEM_END(n, t) t
#define TTL_LIST_ITEMS(n, t) TTL_REPEAT(n,TTL_LIST_ITEM,TTL_LIST_ITEM_END,t)

#define TTL_FUNC_PARAM(n,t) T##n t##n, 
#define TTL_FUNC_PARAM_END(n,t) T##n t##n
#define TTL_FUNC_PARAMS(n, p) TTL_REPEAT(n, TTL_FUNC_PARAM, TTL_FUNC_PARAM_END, p)

#define TTL_FUNC_PPARAM(n,t) P##n t##n, 
#define TTL_FUNC_PPARAM_END(n,t) P##n t##n
#define TTL_FUNC_PPARAMS(n, p) TTL_REPEAT(n, TTL_FUNC_PPARAM, TTL_FUNC_PPARAM_END, p)

#define TTL_ENUM_ITEMS(n, t) TTL_REPEAT(n,TTL_ARG,TTL_ARG_END,t)

#endif //__macro_params__hpp

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
kig
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions