C++ Loki Traits Generating Tuples














































C++ Loki Traits Generating Tuples



GENERATING TUPLES

Many of the readers would have studied tuples in python. They are immutable set of values stored in one variable name in a ordered manner.
Loki library introduces tuples which is similar to GenScatterHierarchy and provides direct field access. 
Let us understand how it gives the direct Field access through an example code

template <class T> struct Holder { T value_; }; typedef GenScatterHierarchy< TYPELIST_3(int, int, int), Holder> Point3D;


To access the field of object , the syntax would be using the static case of the representation of class template and the value_.
static_cast<Holder<string>&>(obj)).value_
But through Field access functions it returns the reference of the value_. Like here it returns Holder<int>&  instead of int&.

 Through tuples we get the direct access using the index of the type provided as shown below:

typedef Tuple<TYPELIST_3(int, int, int)> Point3D; Point3D pt; Field<0>(pt) = 0; Field<1>(pt) = 100; Field<2>(pt) = 300;
The tuple functions in the Loki library are stacked in "Tuple.h".

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 238 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