SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Practical Meta-programming By Reggie Meisler
Topics
How it works in general ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Template mechanics ,[object Object],[object Object]
Template mechanics ,[object Object]
Template mechanics ,[object Object],MyClass<float> goes here MyClass<int> goes here MyClass<int*> goes here
Template mechanics ,[object Object],[object Object]
How it works in general ,[object Object]
How it works in general ,[object Object]
How it works in general ,[object Object]
How it works in general ,[object Object]
Type Traits ,[object Object],[object Object],[object Object]
Math ,[object Object],[object Object]
Fibonacci ,[object Object]
Fibonacci ,[object Object],[object Object]
Real-time vs Compile-time ,[object Object],[object Object],[object Object]
Real-time vs Compile-time ,[object Object],[object Object],[object Object]
Fibonacci Table ,[object Object]
Fibonacci Table ,[object Object],[object Object],[object Object]
Using Fibonacci ,[object Object]
The Meta Tradeoff ,[object Object],[object Object],[object Object],[object Object]
Compile-time recursive function calls ,[object Object],[object Object]
Dot Product ,[object Object]
Dot Product ,[object Object],Always take advantage of auto-type detection!
Dot Product ,[object Object]
Dot Product ,[object Object],We can auto-determine the dimension based on size since T is a POD vector
Approximating Sine ,[object Object],[object Object],[object Object]
Approximating Sine ,[object Object]
Approximating Sine ,[object Object],Floats can’t be declared inside the template class Need radians for Taylor Series formula Our approximated result
Approximating Sine ,[object Object],[object Object],[object Object]
Final Result: FastSine ,[object Object]
Tuples ,[object Object],[object Object]
Tuples ,[object Object],[object Object]
Making a Tuple ,[object Object],This is what I mean by “recursively defined”
Tuple in memory Tuple<int, Tuple<float, Tuple<MyClass>>> data:  int next:  Tuple<float, Tuple<MyClass>> data:  float next:  Tuple<MyClass > data:  MyClass next:  NullType
Tuple<MyClass> Tuple<float, Tuple<MyClass>> Tuple<int, Tuple<float, Tuple<MyClass>>> data:  int data:  float data:  MyClass NullType next next next
Better creation ,[object Object],Not the best solution, but simplifies syntax
Making a Tuple Pt 2 ,[object Object],But can we do something about this indexing mess? Better
Better indexing ,[object Object],It’s a good thing we made those typedefs Making use of template function auto-type detection again
Better indexing ,[object Object]
Delicious Tuple ,[object Object]
Tuple ,[object Object],[object Object],[object Object],[object Object]
SFINAE (Substitution Failure Is Not An Error) ,[object Object]
SFINAE (Substitution Failure Is Not An Error) ,[object Object],[object Object]
Does MyClass have an iterator? ,[object Object]
Nitty Gritty ,[object Object],[object Object],[object Object]
Nitty Gritty ,[object Object],[object Object]
Check for member function ,[object Object]
Nitty Gritty ,[object Object],[object Object]
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
Lap trinh C co ban va nang cao
Lap trinh C co ban va nang caoLap trinh C co ban va nang cao
Lap trinh C co ban va nang cao
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
Data types in c++
Data types in c++ Data types in c++
Data types in c++
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings
 
Generic programming
Generic programmingGeneric programming
Generic programming
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Applicative Functor
Applicative FunctorApplicative Functor
Applicative Functor
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5th
 
Definitions of Functional Programming
Definitions of Functional ProgrammingDefinitions of Functional Programming
Definitions of Functional Programming
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Modern C++
Modern C++Modern C++
Modern C++
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 

Andere mochten auch

Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Ralf Laemmel
 
Generative Software Development. Overview and Examples
Generative Software Development. Overview and ExamplesGenerative Software Development. Overview and Examples
Generative Software Development. Overview and ExamplesEelco Visser
 
Generative Programming In The Large - Applied C++ meta-programming
Generative Programming In The Large - Applied C++ meta-programmingGenerative Programming In The Large - Applied C++ meta-programming
Generative Programming In The Large - Applied C++ meta-programmingSchalk Cronjé
 
Practical Multi-language Generative Programming
Practical Multi-language Generative ProgrammingPractical Multi-language Generative Programming
Practical Multi-language Generative ProgrammingSchalk Cronjé
 
Seeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instructionSeeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instructionSchalk Cronjé
 
A Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing SystemsA Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing SystemsDamien Cassou
 
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingGenerative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingJoel Falcou
 
Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Eugene Lazutkin
 
Japanese Open and Generative Design
Japanese Open and Generative DesignJapanese Open and Generative Design
Japanese Open and Generative DesignYuichi Yazaki
 
Practical C++ Generative Programming
Practical C++ Generative ProgrammingPractical C++ Generative Programming
Practical C++ Generative ProgrammingSchalk Cronjé
 
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk PemulaSeri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk PemulaAgus Kurniawan
 
Probabilistic programming
Probabilistic programmingProbabilistic programming
Probabilistic programmingEli Gottlieb
 
Summary - Transformational-Generative Theory
Summary - Transformational-Generative TheorySummary - Transformational-Generative Theory
Summary - Transformational-Generative TheoryMarielis VI
 
Transformational-Generative Grammar
Transformational-Generative GrammarTransformational-Generative Grammar
Transformational-Generative GrammarRuth Ann Llego
 
Deep structure and surface structure
Deep structure and surface structureDeep structure and surface structure
Deep structure and surface structureAsif Ali Raza
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computingu065932
 

Andere mochten auch (16)

Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)
 
Generative Software Development. Overview and Examples
Generative Software Development. Overview and ExamplesGenerative Software Development. Overview and Examples
Generative Software Development. Overview and Examples
 
Generative Programming In The Large - Applied C++ meta-programming
Generative Programming In The Large - Applied C++ meta-programmingGenerative Programming In The Large - Applied C++ meta-programming
Generative Programming In The Large - Applied C++ meta-programming
 
Practical Multi-language Generative Programming
Practical Multi-language Generative ProgrammingPractical Multi-language Generative Programming
Practical Multi-language Generative Programming
 
Seeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instructionSeeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instruction
 
A Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing SystemsA Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing Systems
 
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingGenerative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
 
Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.Practical pairing of generative programming with functional programming.
Practical pairing of generative programming with functional programming.
 
Japanese Open and Generative Design
Japanese Open and Generative DesignJapanese Open and Generative Design
Japanese Open and Generative Design
 
Practical C++ Generative Programming
Practical C++ Generative ProgrammingPractical C++ Generative Programming
Practical C++ Generative Programming
 
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk PemulaSeri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
 
Probabilistic programming
Probabilistic programmingProbabilistic programming
Probabilistic programming
 
Summary - Transformational-Generative Theory
Summary - Transformational-Generative TheorySummary - Transformational-Generative Theory
Summary - Transformational-Generative Theory
 
Transformational-Generative Grammar
Transformational-Generative GrammarTransformational-Generative Grammar
Transformational-Generative Grammar
 
Deep structure and surface structure
Deep structure and surface structureDeep structure and surface structure
Deep structure and surface structure
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computing
 

Ähnlich wie Practical Meta Programming

btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Robert Pickering
 
C intro
C introC intro
C introKamran
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmersMark Whitaker
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++guestf0562b
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and BeyondComicSansMS
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0Yaser Zhian
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 

Ähnlich wie Practical Meta Programming (20)

btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 
Functions
FunctionsFunctions
Functions
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 
C intro
C introC intro
C intro
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and Beyond
 
C programming
C programmingC programming
C programming
 
Python 3000
Python 3000Python 3000
Python 3000
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
C++11
C++11C++11
C++11
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 

Practical Meta Programming

  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. Tuple in memory Tuple<int, Tuple<float, Tuple<MyClass>>> data: int next: Tuple<float, Tuple<MyClass>> data: float next: Tuple<MyClass > data: MyClass next: NullType
  • 36. Tuple<MyClass> Tuple<float, Tuple<MyClass>> Tuple<int, Tuple<float, Tuple<MyClass>>> data: int data: float data: MyClass NullType next next next
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.