C++ Loki Append TypeList














































C++ Loki Append TypeList



APPENDING TO TYPELIST


Modifying a typelist is not possible, so we can create a new typelist and return by value which contains the output.

ALGORITHM:
Inputs: Typelist TList, type class  T
Outputs: Inner type definition Result

If both TList and are NullType, then the result is NullType
Else
       If TList is NullType and T is a single (non-typlist) type, then Result is a                    typelist  having T as its only element. 
     Else
          If TList is NullType and T is typelist, Result is T.
          Else If TList is not-null, then Result is a typelist having TList::Head as Head and result of appending T to TList::Tail as its tail. 

CODE:
template <class TList, class T> struct Append;
template <> struct Append<NullType, NullType>
{

typedef NullType Result;
};
template <class T> struct Append<NullType, T>
{

typedef TYPELIST_1(T) Result;
};
template <class Head, class Tail>
struct Append<NullType, Typelist<Head, Tail> >
{

typedef Typelist<Head, Tail> Result;
};
template <class Head, class Tail, class T>
struct Append<Typelist<Head, Tail>, T>
{

typedef Typelist<Head,
typename Append<Tail, T>::Result>
Result;
};


EXPLANATION

Partial specialization of Append recursively represents the append template.
There is a mixed operation for single types and typelists.
The list of all signed numeric data types in C++ is:

typedef Append<SignedIntegrals, TYPELIST_3(float, double, long double)>::Result SignedTypes;


More Articles of Abhinav Verma:

Name Views Likes
C++ Loki Abstract Factory Implementation 575 1
C++ Loki SmallObject Compiler Working 403 1
C++ Loki SmallObject 410 1
C++ Loki Abstract Factory Interface 470 1
C++ Loki Double Dispatching 350 2
C++ Loki SmallObjAllocator 370 2
C++ Loki Abstract Factory 353 2
C++ Loki Small Objects Allocation Methods 293 1
C++ Loki The Fixed Size Allocator 442 1
C++ Loki Necessity of Multi-Methods 255 1
C++ Loki Chunks 345 1
C++ Loki Packing Order of Small Object Allocator 275 2
C++ Loki Multimethods Polymorphism 285 2
C++ Loki How does memory allocator works? 275 1
C++ Loki Default Storage Allocator 271 1
C++ Loki Multimethods 348 1
C++ Loki Small Object Allocator 357 1
C++ Loki Techniques Compile Time Affirmations 262 1
C++ Loki Typelist Linear Hierarchy 266 1
C++ Loki Techniques type_info 239 1
C++ Loki Traits Generating Tuples 237 1
C++ Loki Techniques Partial Template Specialization 245 1
C++ Loki Typelist Generating Scattered Hierarchy 307 1
C++ Loki Techniques Select 247 1
C++ Loki Clubbing TypeList 235 1
C++ Loki Techniques Traits 220 1
C++ Loki TypeList Substituting Elements 236 1
C++ Loki Techniques Local Classes 222 1
C++ Loki TypeList Deleting Duplicated 212 1
C++ Loki Techniques Introduction 216 1
C++ Loki Effacing type from typelist 245 1
C++ Loki Append TypeList 274 1
C++ Loki Mouldering Classes 224 1
C++ Loki Searching TypeList 219 1
C++ Loki Smart Pointer Compatibility of Policies 241 1
C++ Loki TypeList Indexed Access 236 1
C++ Loki Smart Pointer Structure Customization 230 1
C++ Loki Length of TypeList 237 1
C++ Loki Smart Pointer Threading Model and Checking Policy 229 1
C++ Loki Voluntary Functionality through Incomplete Initialization 201 1
C++ Loki Policy Class Destructor 244 1
C++ Loki Enriched Policies 215 1
C++ Loki Policy Classes with Template Template Parameter and Member functions 219 1
C++ Loki Kernel of Policy Classes 221 1
C++ Loki Templates in design 227 1
C++ Loki Do-it-All Interface & Multiple Inheritance 230 1
C++ Loki Policy Based Design 288 2
C++ Loki Introduction 310 2
C++ iomanip ends 284 1
C++ iomanip flush 273 2
C++ iomanip ws 306 2

Comments