SlideShare a Scribd company logo

Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spring 2019

Object-oriented programming has been criticized a lot. Every now and then some article or talk appears denouncing it and proclaiming that it's dead. This talk will do the opposite. It defends OOP and presents many modern libraries and concepts to show that it's very much alive and kicking.

1 of 93
Download to read offline
5/27/2019 Object-Oriented Programming in Modern C++
https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 1/93
Object-Object-
OrientedOriented
ProgrammingProgramming
in Modern C++in Modern C++
by /Borislav Stanimirov @stanimirovb
5/27/2019 Object-Oriented Programming in Modern C++
https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 2/93
Hello, WorldHello, World
#include <iostream>
int main()
{
std::cout << "Hi, I'm Borislav!n";
std::cout << "These slides are here: https://is.gd/o
return 0;
}
5/27/2019 Object-Oriented Programming in Modern C++
https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 3/93
Hello, WorldHello, World
#include <iostream>
int main()
{
std::cout << "Hi, I'm Borislav!n";
std::cout << "These slides are here: https://is.gd/o
return 0;
}
5/27/2019 Object-Oriented Programming in Modern C++
https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 4/93
BulgariaBulgaria
5/27/2019 Object-Oriented Programming in Modern C++
https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 5/93
Borislav StanimirovBorislav Stanimirov
Mostly a C++ programmer
Mostly a game programmer
Recently working on medical software
Open-source programmer
github.com/iboB
5/27/2019 Object-Oriented Programming in Modern C++
https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 6/93
Business LogicBusiness Logic
Ad

Recommended

More Related Content

What's hot

C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
 
2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, iohtaitk
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++ Bharat Kalia
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...vtunotesbysree
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for EngineeringVincenzo De Florio
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteachingeteaching
 

What's hot (20)

Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
 
C programming
C programmingC programming
C programming
 
Deep C
Deep CDeep C
Deep C
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
Oop l2
Oop l2Oop l2
Oop l2
 
C vs c++
C vs c++C vs c++
C vs c++
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
C Programming
C ProgrammingC Programming
C Programming
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
C programming
C programmingC programming
C programming
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for Engineering
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 

Similar to Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spring 2019

High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14Matthieu Garrigues
 
Object oriented slides
Object oriented slidesObject oriented slides
Object oriented slidesahad nadeem
 
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTERC++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTERgroversimrans
 
CAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxCAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxSurajgroupsvideo
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++Manoj Kumar
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIYoni Davidson
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Serverless survival kit
Serverless survival kitServerless survival kit
Serverless survival kitSteve Houël
 

Similar to Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spring 2019 (20)

basics of c++
basics of c++basics of c++
basics of c++
 
basics of c++
basics of c++basics of c++
basics of c++
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
Lecture 11
Lecture 11Lecture 11
Lecture 11
 
Object oriented slides
Object oriented slidesObject oriented slides
Object oriented slides
 
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTERC++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
C++ TRAINING IN AMBALA CANTT! BATRA COMPUTER CENTER
 
CAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxCAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptx
 
What is c++ programming
What is c++ programmingWhat is c++ programming
What is c++ programming
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Unit i
Unit iUnit i
Unit i
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Serverless survival kit
Serverless survival kitServerless survival kit
Serverless survival kit
 
VR Workshop #2
VR Workshop #2VR Workshop #2
VR Workshop #2
 
Session 1 - c++ intro
Session   1 - c++ introSession   1 - c++ intro
Session 1 - c++ intro
 

More from corehard_by

C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...corehard_by
 
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...corehard_by
 
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений ОхотниковC++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотниковcorehard_by
 
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр ТитовC++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титовcorehard_by
 
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...corehard_by
 
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья ШишковC++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишковcorehard_by
 
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...corehard_by
 
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...corehard_by
 
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...corehard_by
 
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...corehard_by
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...corehard_by
 
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...corehard_by
 
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел ФилоновC++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филоновcorehard_by
 
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan ČukićC++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukićcorehard_by
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia KazakovaC++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakovacorehard_by
 
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон ПолухинC++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухинcorehard_by
 
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...corehard_by
 
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019corehard_by
 
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019corehard_by
 
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019corehard_by
 

More from corehard_by (20)

C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
 
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
 
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений ОхотниковC++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
 
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр ТитовC++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
 
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
 
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья ШишковC++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
 
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
 
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
 
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
 
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
 
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
 
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел ФилоновC++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
 
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan ČukićC++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia KazakovaC++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
 
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон ПолухинC++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
 
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
 
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
 
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
 
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
 

Recently uploaded

Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Umar Saif
 
How we think about an advisor tech stack
How we think about an advisor tech stackHow we think about an advisor tech stack
How we think about an advisor tech stackSummit
 
"AIRe - AI Reliability Engineering", Denys Vasyliev
"AIRe - AI Reliability Engineering", Denys Vasyliev"AIRe - AI Reliability Engineering", Denys Vasyliev
"AIRe - AI Reliability Engineering", Denys VasylievFwdays
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17Ana-Maria Mihalceanu
 
"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor FesenkoFwdays
 
AI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvementAI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvementMimmo Squillace
 
IT Nation Evolve event 2024 - Quarter 1
IT Nation Evolve event 2024  - Quarter 1IT Nation Evolve event 2024  - Quarter 1
IT Nation Evolve event 2024 - Quarter 1Inbay UK
 
M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____Aathiraju
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manualDomotica daVinci
 
Building Products That Think- Bhaskaran Srinivasan & Ashish Gupta
Building Products That Think- Bhaskaran Srinivasan & Ashish GuptaBuilding Products That Think- Bhaskaran Srinivasan & Ashish Gupta
Building Products That Think- Bhaskaran Srinivasan & Ashish GuptaISPMAIndia
 
Importance of magazines in education ppt
Importance of magazines in education pptImportance of magazines in education ppt
Importance of magazines in education pptsafnarafeek2002
 
Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?MENGSAYLOEM1
 
Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...
Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...
Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...DianaGray10
 
Curtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfCurtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfDomotica daVinci
 
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...ISPMAIndia
 
My self introduction to know others abut me
My self  introduction to know others abut meMy self  introduction to know others abut me
My self introduction to know others abut meManoj Prabakar B
 
Bit N Build Poland
Bit N Build PolandBit N Build Poland
Bit N Build PolandGDSC PJATK
 
"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google
"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google
"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, GoogleISPMAIndia
 
Automate Your Master Data Processes for Shared Service Center Excellence
Automate Your Master Data Processes for Shared Service Center ExcellenceAutomate Your Master Data Processes for Shared Service Center Excellence
Automate Your Master Data Processes for Shared Service Center ExcellencePrecisely
 
Q1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IP
Q1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IPQ1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IP
Q1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IPMemory Fabric Forum
 

Recently uploaded (20)

Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
Progress Report: Ministry of IT under Dr. Umar Saif Aug 23-Feb'24
 
How we think about an advisor tech stack
How we think about an advisor tech stackHow we think about an advisor tech stack
How we think about an advisor tech stack
 
"AIRe - AI Reliability Engineering", Denys Vasyliev
"AIRe - AI Reliability Engineering", Denys Vasyliev"AIRe - AI Reliability Engineering", Denys Vasyliev
"AIRe - AI Reliability Engineering", Denys Vasyliev
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
 
"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko"Platform Engineering with Development Containers", Igor Fesenko
"Platform Engineering with Development Containers", Igor Fesenko
 
AI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvementAI Act & Standardization: UNINFO involvement
AI Act & Standardization: UNINFO involvement
 
IT Nation Evolve event 2024 - Quarter 1
IT Nation Evolve event 2024  - Quarter 1IT Nation Evolve event 2024  - Quarter 1
IT Nation Evolve event 2024 - Quarter 1
 
M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
 
Building Products That Think- Bhaskaran Srinivasan & Ashish Gupta
Building Products That Think- Bhaskaran Srinivasan & Ashish GuptaBuilding Products That Think- Bhaskaran Srinivasan & Ashish Gupta
Building Products That Think- Bhaskaran Srinivasan & Ashish Gupta
 
Importance of magazines in education ppt
Importance of magazines in education pptImportance of magazines in education ppt
Importance of magazines in education ppt
 
Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?Are Human-generated Demonstrations Necessary for In-context Learning?
Are Human-generated Demonstrations Necessary for In-context Learning?
 
Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...
Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...
Automation Ops Series: Session 1 - Introduction and setup DevOps for UiPath p...
 
Curtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfCurtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdf
 
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
AI MODELS USAGE IN FINTECH PRODUCTS: PM APPROACH & BEST PRACTICES by Kasthuri...
 
My self introduction to know others abut me
My self  introduction to know others abut meMy self  introduction to know others abut me
My self introduction to know others abut me
 
Bit N Build Poland
Bit N Build PolandBit N Build Poland
Bit N Build Poland
 
"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google
"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google
"The Transformative Power of AI and Open Challenges" by Dr. Manish Gupta, Google
 
Automate Your Master Data Processes for Shared Service Center Excellence
Automate Your Master Data Processes for Shared Service Center ExcellenceAutomate Your Master Data Processes for Shared Service Center Excellence
Automate Your Master Data Processes for Shared Service Center Excellence
 
Q1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IP
Q1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IPQ1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IP
Q1 Memory Fabric Forum: Building Fast and Secure Chips with CXL IP
 

Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spring 2019

  • 1. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 1/93 Object-Object- OrientedOriented ProgrammingProgramming in Modern C++in Modern C++ by /Borislav Stanimirov @stanimirovb
  • 2. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 2/93 Hello, WorldHello, World #include <iostream> int main() { std::cout << "Hi, I'm Borislav!n"; std::cout << "These slides are here: https://is.gd/o return 0; }
  • 3. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 3/93 Hello, WorldHello, World #include <iostream> int main() { std::cout << "Hi, I'm Borislav!n"; std::cout << "These slides are here: https://is.gd/o return 0; }
  • 4. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 4/93 BulgariaBulgaria
  • 5. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 5/93 Borislav StanimirovBorislav Stanimirov Mostly a C++ programmer Mostly a game programmer Recently working on medical software Open-source programmer github.com/iboB
  • 6. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 6/93 Business LogicBusiness Logic
  • 7. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 7/93 A part of a program which deals with the real world rules that determine how data is obtained, stored and processed.
  • 8. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 8/93 The part which deals with the software's purpose int a; int b; cin >> a >> b; cout << a + b << 'n'; Business logic: adding two integers
  • 9. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 9/93 The part which deals with the software's purpose int a; int b; cin >> a >> b; cout << a + b << 'n'; Business logic: adding two integers
  • 10. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 10/93 The part which deals with the software's purpose FirstInteger a; SecondInteger b; input.obtainValues(a, b); gui.display(a + b); Business logic: adding two integers
  • 11. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 11/93 The part which deals with the software's purpose FirstInteger a; SecondInteger b; input.obtainValues(a, b); gui.display(a + b); Business logic: adding two integers
  • 12. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 12/93 Presentation, i/o... FirstInteger a; SecondInteger b; input.obtainValues(a, b); gui.display(a + b); Non-business logic
  • 13. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 13/93 Complex software doesn't mean complex business logic.
  • 14. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 14/93
  • 15. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 15/93 Light Source Scene Object Shadow Ray View Ray Image Camera _
  • 16. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 16/93 Light Source Scene Object Shadow Ray View Ray Image Camera Simple. Right?
  • 17. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 17/93
  • 18. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 18/93
  • 19. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 19/93
  • 20. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 20/93
  • 21. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 21/93 What do we have here?What do we have here? Websites - JS, C#, Java, Ruby... Gameplay - lua, C#, Python... CAD - Python, C#... Enterprise - Everything but C++ People don't seem to want to write business logic in C++ Note that there still is a lot of underlying C++ in such projects
  • 22. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 22/93 Well... is there a problem with that?
  • 23. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 23/93 Problems with thatProblems with that The code is slower There is more complexity in the binding layer There are duplicated functionalities (which means duplicated bugs)
  • 24. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 24/93 Why don't people use C++?
  • 25. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 25/93 Some reasonsSome reasons Buld times Hotswap Testing But (I think) most importantly...
  • 26. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 26/93 OOPOOP ... with dynamic polymorphism
  • 27. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 27/93 Criticism of OOPCriticism of OOP You want a banana, but with it you also get the gorilla and the entire jungle It dangerously couples the data with the functionality It's not reusable It's slow People forget that C++ is an OOP language
  • 28. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 28/93 Defense of OOPDefense of OOP Many cricisims target concrete implementations Many are about misuse of OOP Some are about misconceptions of OOP But most importantly...
  • 29. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 29/93 Software is written by human beings
  • 30. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 30/93 Human beings think in terms of objects
  • 31. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 31/93 Which languages thrive in fields with heavy business logic? Almost all are object-oriented ones.
  • 32. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 32/93 Powerful OOPPowerful OOP function f(shape) { // Everything that has a draw method works shape.draw(); } Square = function () { this.draw = function() { console.log("Square"); } }; Circle = function () { this.draw = function() { console.log("Circle"); } }; f(new Square); f(new Circle);
  • 33. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 33/93 Vanilla C++ OOPVanilla C++ OOP struct Shape { virtual void draw(ostream& out) const = 0; } void f(const Shape& s) { s.draw(cout); } struct Square : public Shape { virtual void draw(ostream& out) const override { }; struct Circle : public Shape { virtual void draw(ostream& out) const override { }; int main() { f(Square{}); f(Circle{}); }
  • 34. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 34/93 OOP isn't modern C++OOP isn't modern C++ However modern C++ is a pretty powerful language.
  • 35. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 35/93 Polymorphic type-erasure wrappersPolymorphic type-erasure wrappers , , ,Boost.TypeErasure Dyno Folly.Poly [Boost].TE using Shape = Library_Magic(void, draw, (ostream&)); void f(const Shape& s) { s.draw(cout); } struct Square { void draw(ostream& out) const { out << "Squaren"; } }; struct Circle { void draw(ostream& out) const { out << "Circlen"; } }; int main() { f(Square{}); f(Circle{}); }
  • 36. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 36/93 Polymorphic type-erasure wrappersPolymorphic type-erasure wrappers , , ,Boost.TypeErasure Dyno Folly.Poly [Boost].TE using Shape = Library_Magic(void, draw, (ostream&)); void f(const Shape& s) { s.draw(cout); } struct Square { void draw(ostream& out) const { out << "Squaren"; } }; struct Circle { void draw(ostream& out) const { out << "Circlen"; } }; int main() { f(Square{}); f(Circle{}); }
  • 37. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 37/93 How does this work?How does this work? struct Shape { // virtual table std::function<void(ostream&)> draw; std::function<int()> area; // fill the virtual table when constructing template <typename T> Shape(const T& t) { draw = std::bind(&T::draw, &t); area = std::bind(&T::area, &t); } };
  • 38. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 38/93 How does this work?How does this work? struct Shape { // virtual table std::function<void(ostream&)> draw; std::function<int()> area; // fill the virtual table when constructing template <typename T> Shape(const T& t) { draw = std::bind(&T::draw, &t); area = std::bind(&T::area, &t); } };
  • 39. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 39/93 How does this work?How does this work? struct Shape { // virtual table std::function<void(ostream&)> draw; std::function<int()> area; // fill the virtual table when constructing template <typename T> Shape(const T& t) { draw = std::bind(&T::draw, &t); area = std::bind(&T::area, &t); } }; This, of course, is a simple and naive implementation. There's lots of room for optimization
  • 40. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 40/93 Faster dispatchFaster dispatch struct Shape { // virtual table const void* m_obj; void (*m_draw)(const void*, ostream&); void draw() const { return m_draw(m_obj); } template <typename T> Shape(const T& t) { m_obj = &t; m_draw = [](const void* obj, ostream& out) { auto t = reinterpret_cast<const T*>(obj); t->draw(out); }; } };
  • 41. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 41/93 Faster dispatchFaster dispatch struct Shape { // virtual table const void* m_obj; void (*m_draw)(const void*, ostream&); void draw() const { return m_draw(m_obj); } template <typename T> Shape(const T& t) { m_obj = &t; m_draw = [](const void* obj, ostream& out) { auto t = reinterpret_cast<const T*>(obj); t->draw(out); }; } };
  • 42. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 42/93 Faster dispatchFaster dispatch struct Shape { // virtual table const void* m_obj; void (*m_draw)(const void*, ostream&); void draw() const { return m_draw(m_obj); } template <typename T> Shape(const T& t) { m_obj = &t; m_draw = [](const void* obj, ostream& out) { auto t = reinterpret_cast<const T*>(obj); t->draw(out); }; } };
  • 43. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 43/93 Powerful OOPPowerful OOP Square.prototype.area = function() { return this.side * this.side; } Circle.prototype.area = function() { return this.radius * this.radius * Math.PI; } s = new Square; s.side = 5; console.log(s.area()); // 25
  • 44. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 44/93 Vanilla C++ OOPVanilla C++ OOP struct Shape { virtual void draw(ostream& out) const = 0; } struct Square : public Shape { virtual void draw(ostream& out) const override { int side; }; int main() { shared_ptr<Shape> ptr = make_shared<Square>(); cout << ptr->area() << 'n'; // ?? }
  • 45. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 45/93 Vanilla C++ OOPVanilla C++ OOP struct Shape { virtual void draw(ostream& out) const = 0; virtual double area() const = 0; } struct Square : public Shape { virtual void draw(ostream& out) const override { virtual double area() const override { return si double side; }; int main() { shared_ptr<Shape> ptr = make_shared<Square>(); cout << ptr->area() << 'n'; } And what if we can't just edit the classes?
  • 46. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 46/93 Open methodsOpen methods Not to be confused with extension methods or UCS ,[Boost].TE yomm2 declare_method(double, area, (virtual_<const Shape&> s); define_method(double, area, (const Square& s) { return s.area * s.area; } int main() { shared_ptr<Shape> ptr = make_shared<Square>(); cout << area(ptr) << 'n'; }
  • 47. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 47/93 Open methodsOpen methods Not to be confused with extension methods or UCS ,[Boost].TE yomm2 declare_method(double, area, (virtual_<const Shape&> s); define_method(double, area, (const Square& s) { return s.area * s.area; } int main() { shared_ptr<Shape> ptr = make_shared<Square>(); cout << area(ptr) << 'n'; }
  • 48. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 48/93 How does this work?How does this work? // declare method using area_func = double (*)(const Shape*); using area_func_getter = area_func (*)(const Shape*); std::vector<area_func_getter> area_getters; double area(Shape* s) { for(auto g : area_getters) { auto func = g(); if(func) return func(s); } throw error("Object doesn't implement area"); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } area_func area_for_square_getter(const Shape* s) { return dynamic_cast<const Square*>(s) ? area_for_squ } auto register_area_for_square = []() {
  • 49. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 49/93 How does this work?How does this work? // declare method using area_func = double (*)(const Shape*); using area_func_getter = area_func (*)(const Shape*); std::vector<area_func_getter> area_getters; double area(Shape* s) { for(auto g : area_getters) { auto func = g(); if(func) return func(s); } throw error("Object doesn't implement area"); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } area_func area_for_square_getter(const Shape* s) { return dynamic_cast<const Square*>(s) ? area_for_squ } auto register_area_for_square = []() {
  • 50. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 50/93 How does this work?How does this work? // declare method using area_func = double (*)(const Shape*); using area_func_getter = area_func (*)(const Shape*); std::vector<area_func_getter> area_getters; double area(Shape* s) { for(auto g : area_getters) { auto func = g(); if(func) return func(s); } throw error("Object doesn't implement area"); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } area_func area_for_square_getter(const Shape* s) { return dynamic_cast<const Square*>(s) ? area_for_squ } auto register_area_for_square = []() {
  • 51. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 51/93 How does this work?How does this work? // declare method using area_func = double (*)(const Shape*); using area_func_getter = area_func (*)(const Shape*); std::vector<area_func_getter> area_getters; double area(Shape* s) { for(auto g : area_getters) { auto func = g(); if(func) return func(s); } throw error("Object doesn't implement area"); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } area_func area_for_square_getter(const Shape* s) { return dynamic_cast<const Square*>(s) ? area_for_squ } auto register_area_for_square = []() {
  • 52. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 52/93 How does this work?How does this work? // declare method using area_func = double (*)(const Shape*); using area_func_getter = area_func (*)(const Shape*); std::vector<area_func_getter> area_getters; double area(Shape* s) { for(auto g : area_getters) { auto func = g(); if(func) return func(s); } throw error("Object doesn't implement area"); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } area_func area_for_square_getter(const Shape* s) { return dynamic_cast<const Square*>(s) ? area_for_squ } auto register_area_for_square = []() {
  • 53. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 53/93 Optimize the dispatchOptimize the dispatch // declare method using area_func = double (*)(const Shape*); std::unordered_map<std::type_index, area_func> area_gett double area(Shape* s) { auto f = area_getters.find(std::type_index(typeid(*s if (f == area_getters.end()) throw error("Object doe return f->second(s); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } auto register_area_for_square = []() { area_getters[std::type_index(typeid(Square))] = area return area_getters.size(); }(); double area_for_square(const Square&) // user defines af
  • 54. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 54/93 Optimize the dispatchOptimize the dispatch // declare method using area_func = double (*)(const Shape*); std::unordered_map<std::type_index, area_func> area_gett double area(Shape* s) { auto f = area_getters.find(std::type_index(typeid(*s if (f == area_getters.end()) throw error("Object doe return f->second(s); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } auto register_area_for_square = []() { area_getters[std::type_index(typeid(Square))] = area return area_getters.size(); }(); double area_for_square(const Square&) // user defines af
  • 55. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 55/93 Optimize the dispatchOptimize the dispatch // declare method using area_func = double (*)(const Shape*); std::unordered_map<std::type_index, area_func> area_gett double area(Shape* s) { auto f = area_getters.find(std::type_index(typeid(*s if (f == area_getters.end()) throw error("Object doe return f->second(s); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } auto register_area_for_square = []() { area_getters[std::type_index(typeid(Square))] = area return area_getters.size(); }(); double area_for_square(const Square&) // user defines af
  • 56. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 56/93 Optimize the dispatchOptimize the dispatch // declare method using area_func = double (*)(const Shape*); std::unordered_map<std::type_index, area_func> area_gett double area(Shape* s) { auto f = area_getters.find(std::type_index(typeid(*s if (f == area_getters.end()) throw error("Object doe return f->second(s); } // define method double area_for_square(const Square&); double area_for_square_call(const Shape* s) { auto square = static_cast<const Square*>(s); return area_for_square(*square); } auto register_area_for_square = []() { area_getters[std::type_index(typeid(Square))] = area return area_getters.size(); }(); double area_for_square(const Square&) // user defines af
  • 57. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 57/93 Powerful OOPPowerful OOP multi sub collide(Square $s, Square $c) { collide_square_square($s, $c); } multi sub collide(Circle $s, Circle $c) { collide_circle_circle($s, $c); } multi sub collide(Square $s, Circle $c) { collide_square_circle($s, $c); } multi sub collide(Circle $c, Square $s) { collide_square_circle($s, $c); } my $s1 = get_random_shape; my $s2 = get_random_shape; say "Collision: " ~ collide($s1, $s2);
  • 58. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 58/93 Vanilla C++ OOPVanilla C++ OOP struct Shape { virtual bool collide(const Shape* other) const = virtual bool collideImpl(const Square*) const = virtual bool collideImpl(const Circle*) const = virtual bool collideImpl(const Triangle*) const } struct Square : public Shape { virtual bool collide(const Shape* other) const o return other->collideImpl(this); } virtual bool collideImpl(const Square*) const ov virtual bool collideImpl(const Circle*) const ov virtual bool collideImpl(const Triangle*) const }; // ... shared_ptr<Shape> s1 = get_random_shape(); shared_ptr<Shape> s2 = get_random_shape(); cout << "Collision: " << s1->collide(s2.get()) << '
  • 59. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 59/93 Vanilla C++ OOPVanilla C++ OOP struct Shape { virtual bool collide(const Shape* other) const = virtual bool collideImpl(const Square*) const = virtual bool collideImpl(const Circle*) const = virtual bool collideImpl(const Triangle*) const } struct Square : public Shape { virtual bool collide(const Shape* other) const o return other->collideImpl(this); /* copy thi } virtual bool collideImpl(const Square*) const ov virtual bool collideImpl(const Circle*) const ov virtual bool collideImpl(const Triangle*) const }; // ... shared_ptr<Shape> s1 = get_random_shape(); shared_ptr<Shape> s2 = get_random_shape(); cout << "Collision: " << s1->collide(s2.get()) << '
  • 60. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 60/93 Vanilla C++ OOPVanilla C++ OOP struct Shape { virtual bool collide(const Shape* other) const = virtual bool collideImpl(const Square*) const = virtual bool collideImpl(const Circle*) const = virtual bool collideImpl(const Triangle*) const } struct Square : public Shape { virtual bool collide(const Shape* other) const o return other->collideImpl(this); } virtual bool collideImpl(const Square*) const ov virtual bool collideImpl(const Circle*) const ov virtual bool collideImpl(const Triangle*) const }; // ... shared_ptr<Shape> s1 = get_random_shape(); shared_ptr<Shape> s2 = get_random_shape(); cout << "Collision: " << s1->collide(s2.get()) << '
  • 61. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 61/93 Multiple dispatch (Multimethods)Multiple dispatch (Multimethods) ,yomm2 Folly.Poly declare_method(bool, collide, (virtual_<const Shape&> s1, (virtual_<const Shape&> define_method(bool, collide, (const Square& s, const Cir { return collide_square_circle(s, c); } define_method(bool, collide, (const Circle& c, const Squ { return collide_square_circle(s, c); } // ... shared_ptr<Shape> s1 = get_random_shape(); shared_ptr<Shape> s2 = get_random_shape(); cout << "Collision: " << collide(*s1, *s2) << 'n';
  • 62. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 62/93 How does this work?How does this work? struct collide_index { size_t first; size_t second; }; size_t hash(collide_index); // implement as you wish collide_index circle_square = { std::type_index(typeid(Circle).hash_code(), std::type_index(typeid(Square).hash_code(), };
  • 63. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 63/93 Powerful OOPPowerful OOP module FlyingCreature def move_to(target) puts can_move_to?(target) ? "flying to #{target}" : "can't fly to #{target}" end def can_move_to?(target) true # flying creatures don't care end end module AfraidOfEvens def can_move_to?(target) target % 2 != 0 end end a = Object.new a.extend(FlyingCreature) a.move_to(10) # -> flying to 10 a.extend(AfraidOfEvens) a.move_to(10) # -> can’t fly to 10
  • 64. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 64/93 Powerful OOPPowerful OOP module FlyingCreature def move_to(target) puts can_move_to?(target) ? "flying to #{target}" : "can't fly to #{target}" end def can_move_to?(target) true # flying creatures don't care end end module AfraidOfEvens def can_move_to?(target) target % 2 != 0 end end a = Object.new a.extend(FlyingCreature) a.move_to(10) # -> flying to 10 a.extend(AfraidOfEvens) a.move_to(10) # -> can’t fly to 10
  • 65. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 65/93 Powerful OOPPowerful OOP module FlyingCreature def move_to(target) puts can_move_to?(target) ? "flying to #{target}" : "can't fly to #{target}" end def can_move_to?(target) true # flying creatures don't care end end module AfraidOfEvens def can_move_to?(target) target % 2 != 0 end end a = Object.new a.extend(FlyingCreature) a.move_to(10) # -> flying to 10 a.extend(AfraidOfEvens) a.move_to(10) # -> can’t fly to 10
  • 66. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 66/93 Powerful OOPPowerful OOP module FlyingCreature def move_to(target) puts can_move_to?(target) ? "flying to #{target}" : "can't fly to #{target}" end def can_move_to?(target) true # flying creatures don't care end end module AfraidOfEvens def can_move_to?(target) target % 2 != 0 end end a = Object.new a.extend(FlyingCreature) a.move_to(10) # -> flying to 10 a.extend(AfraidOfEvens) a.move_to(10) # -> can’t fly to 10
  • 67. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 67/93 Powerful OOPPowerful OOP module FlyingCreature def move_to(target) puts can_move_to?(target) ? "flying to #{target}" : "can't fly to #{target}" end def can_move_to?(target) true # flying creatures don't care end end module AfraidOfEvens def can_move_to?(target) target % 2 != 0 end end a = Object.new a.extend(FlyingCreature) a.move_to(10) # -> flying to 10 a.extend(AfraidOfEvens) a.move_to(10) # -> can’t fly to 10
  • 68. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 68/93 Powerful OOPPowerful OOP module FlyingCreature def move_to(target) puts can_move_to?(target) ? "flying to #{target}" : "can't fly to #{target}" end def can_move_to?(target) true # flying creatures don't care end end module AfraidOfEvens def can_move_to?(target) target % 2 != 0 end end a = Object.new a.extend(FlyingCreature) a.move_to(10) # -> flying to 10 a.extend(AfraidOfEvens) a.move_to(10) # -> can’t fly to 10
  • 69. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 69/93 Vanilla C++ OOPVanilla C++ OOP // ???
  • 70. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 70/93 Vanilla C++ OOPVanilla C++ OOP struct Object { shared_ptr<ICanMoveTo> m_canMoveTo; shared_ptr<IMoveTo> m_moveTo; // ... every possible method ever bool canMoveTo(int target) const { return m_canMoveTo->call(target); } // ... every possible method ever (again) void extend(shared_ptr<Creature> c) { c->setObject(this); m_canMoveTo = c; m_moveTo = c; } void extend(shared_ptr<ICanMoveTo> cmt) { cmt->setObject(this); m_canMoveTo = cmt; } // ... every possible extension ever };
  • 71. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 71/93 Vanilla C++ OOPVanilla C++ OOP // ... components // ... virtual inheritence // ... A LOT OF CODE Object o; o.extend(make_shared<FlyingCreature>()); o.moveTo(10); // flying to 10 o.extend(make_shared<AfraidOfEvens>()); o.moveTo(10); // can't fly to 10
  • 72. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 72/93 Dynamic MixinsDynamic Mixins DynaMix DYNAMIX_MESSAGE_1(void, moveTo, int, target); DYNAMIX_CONST_MESSAGE_1(bool, canMoveTo, int, target); struct FlyingCreature { void moveTo(int target) { cout << (::canMoveTo(dm_this, target) ? "flying to " : "can't fly to ") << target << 'n'; } bool canMoveTo(int target) const { return true; } }; DYNAMIX_DEFINE_MIXIN(FlyingCreature, moveTo_msg & canMoveTo_msg) struct AfraidOfEvens { bool canMoveTo(int target) const { return target % 2 != 0; } }; DYNAMIX_DEFINE_MIXIN(AfraidOfEvens, priority(1, canMoveTo_msg)); int main() { object o; mutate(o).add<FlyingCreature>(); moveTo(o, 10); // flying to 10 mutate(o).add<AfraidOfEvens>(); moveTo(o, 10); // can't fly to 10 }
  • 73. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 73/93 Dynamic MixinsDynamic Mixins DynaMix DYNAMIX_MESSAGE_1(void, moveTo, int, target); DYNAMIX_CONST_MESSAGE_1(bool, canMoveTo, int, target); struct FlyingCreature { void moveTo(int target) { cout << (::canMoveTo(dm_this, target) ? "flying to " : "can't fly to ") << target << 'n'; } bool canMoveTo(int target) const { return true; } }; DYNAMIX_DEFINE_MIXIN(FlyingCreature, moveTo_msg & canMoveTo_msg) struct AfraidOfEvens { bool canMoveTo(int target) const { return target % 2 != 0; } }; DYNAMIX_DEFINE_MIXIN(AfraidOfEvens, priority(1, canMoveTo_msg)); int main() { object o; mutate(o).add<FlyingCreature>(); moveTo(o, 10); // flying to 10 mutate(o).add<AfraidOfEvens>(); moveTo(o, 10); // can't fly to 10 }
  • 74. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 74/93 Dynamic MixinsDynamic Mixins DynaMix DYNAMIX_MESSAGE_1(void, moveTo, int, target); DYNAMIX_CONST_MESSAGE_1(bool, canMoveTo, int, target); struct FlyingCreature { void moveTo(int target) { cout << (::canMoveTo(dm_this, target) ? "flying to " : "can't fly to ") << target << 'n'; } bool canMoveTo(int target) const { return true; } }; DYNAMIX_DEFINE_MIXIN(FlyingCreature, moveTo_msg & canMoveTo_msg) struct AfraidOfEvens { bool canMoveTo(int target) const { return target % 2 != 0; } }; DYNAMIX_DEFINE_MIXIN(AfraidOfEvens, priority(1, canMoveTo_msg)); int main() { object o; mutate(o).add<FlyingCreature>(); moveTo(o, 10); // flying to 10 mutate(o).add<AfraidOfEvens>(); moveTo(o, 10); // can't fly to 10 }
  • 75. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 75/93 Dynamic MixinsDynamic Mixins DynaMix DYNAMIX_MESSAGE_1(void, moveTo, int, target); DYNAMIX_CONST_MESSAGE_1(bool, canMoveTo, int, target); struct FlyingCreature { void moveTo(int target) { cout << (::canMoveTo(dm_this, target) ? "flying to " : "can't fly to ") << target << 'n'; } bool canMoveTo(int target) const { return true; } }; DYNAMIX_DEFINE_MIXIN(FlyingCreature, moveTo_msg & canMoveTo_msg) struct AfraidOfEvens { bool canMoveTo(int target) const { return target % 2 != 0; } }; DYNAMIX_DEFINE_MIXIN(AfraidOfEvens, priority(1, canMoveTo_msg)); int main() { object o; mutate(o).add<FlyingCreature>(); moveTo(o, 10); // flying to 10 mutate(o).add<AfraidOfEvens>(); moveTo(o, 10); // can't fly to 10 }
  • 76. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 76/93 Dynamic MixinsDynamic Mixins DynaMix DYNAMIX_MESSAGE_1(void, moveTo, int, target); DYNAMIX_CONST_MESSAGE_1(bool, canMoveTo, int, target); struct FlyingCreature { void moveTo(int target) { cout << (::canMoveTo(dm_this, target) ? "flying to " : "can't fly to ") << target << 'n'; } bool canMoveTo(int target) const { return true; } }; DYNAMIX_DEFINE_MIXIN(FlyingCreature, moveTo_msg & canMoveTo_msg) struct AfraidOfEvens { bool canMoveTo(int target) const { return target % 2 != 0; } }; DYNAMIX_DEFINE_MIXIN(AfraidOfEvens, priority(1, canMoveTo_msg)); int main() { object o; mutate(o).add<FlyingCreature>(); moveTo(o, 10); // flying to 10 mutate(o).add<AfraidOfEvens>(); moveTo(o, 10); // can't fly to 10 }
  • 77. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 77/93 Dynamic MixinsDynamic Mixins DynaMix DYNAMIX_MESSAGE_1(void, moveTo, int, target); DYNAMIX_CONST_MESSAGE_1(bool, canMoveTo, int, target); struct FlyingCreature { void moveTo(int target) { cout << (::canMoveTo(dm_this, target) ? "flying to " : "can't fly to ") << target << 'n'; } bool canMoveTo(int target) const { return true; } }; DYNAMIX_DEFINE_MIXIN(FlyingCreature, moveTo_msg & canMoveTo_msg) struct AfraidOfEvens { bool canMoveTo(int target) const { return target % 2 != 0; } }; DYNAMIX_DEFINE_MIXIN(AfraidOfEvens, priority(1, canMoveTo_msg)); int main() { object o; mutate(o).add<FlyingCreature>(); moveTo(o, 10); // flying to 10 mutate(o).add<AfraidOfEvens>(); moveTo(o, 10); // can't fly to 10 }
  • 78. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 78/93 EEyyee ccaannddyy ttiimmee!! MixQuest: github.com/iboB/mixquest
  • 79. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 79/93 How does this work?How does this work? // message_registry struct message_info {} std::vector<message_info*> msg_infos; // register mixin auto moveTo_id = []() { msg_infos.emplace_back(); return msg_infos.size(); }(); template <typename Mixin> void* moveTo_caller() { return [](void* mixin, int target) { auto m = reintepret_cast<Mixin*>(mixin); m->moveTo(target); }; } void moveTo(object& o, int target);
  • 80. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 80/93 How does this work?How does this work? // message_registry struct message_info {} std::vector<message_info*> msg_infos; // register mixin auto moveTo_id = []() { msg_infos.emplace_back(); return msg_infos.size(); }(); template <typename Mixin> void* moveTo_caller() { return [](void* mixin, int target) { auto m = reintepret_cast<Mixin*>(mixin); m->moveTo(target); }; } void moveTo(object& o, int target);
  • 81. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 81/93 How does this work?How does this work? // message_registry struct message_info {} std::vector<message_info*> msg_infos; // register mixin auto moveTo_id = []() { msg_infos.emplace_back(); return msg_infos.size(); }(); template <typename Mixin> void* moveTo_caller() { return [](void* mixin, int target) { auto m = reintepret_cast<Mixin*>(mixin); m->moveTo(target); }; } void moveTo(object& o, int target);
  • 82. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 82/93 How does this work?How does this work? // message_registry struct message_info {} std::vector<message_info*> msg_infos; // register mixin auto moveTo_id = []() { msg_infos.emplace_back(); return msg_infos.size(); }(); template <typename Mixin> void* moveTo_caller() { return [](void* mixin, int target) { auto m = reintepret_cast<Mixin*>(mixin); m->moveTo(target); }; } void moveTo(object& o, int target);
  • 83. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 83/93 How does this work?How does this work? // mixin_registry struct mixin_info { std::vector<void*> funcs; } std::vector<mixin_info*> mixin_infos; // register mixin auto FlyingCreature_id = []() { auto info = new mixin_type_info; info->funcs.resize(registered_messages.size()); info->funcs[moveTo_id] = moveTo_caller<FlyingCreatur }(); mixin_type_info* info_for(FlyingCreature*) { return mixin_infos[FlyingCreature_id]; }
  • 84. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 84/93 How does this work?How does this work? // mixin_registry struct mixin_info { std::vector<void*> funcs; } std::vector<mixin_info*> mixin_infos; // register mixin auto FlyingCreature_id = []() { auto info = new mixin_type_info; info->funcs.resize(registered_messages.size()); info->funcs[moveTo_id] = moveTo_caller<FlyingCreatur }(); mixin_type_info* info_for(FlyingCreature*) { return mixin_infos[FlyingCreature_id]; }
  • 85. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 85/93 How does this work?How does this work? // mixin_registry struct mixin_info { std::vector<void*> funcs; } std::vector<mixin_info*> mixin_infos; // register mixin auto FlyingCreature_id = []() { auto info = new mixin_type_info; info->funcs.resize(registered_messages.size()); info->funcs[moveTo_id] = moveTo_caller<FlyingCreatur }(); mixin_type_info* info_for(FlyingCreature*) { return mixin_infos[FlyingCreature_id]; }
  • 86. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 86/93 How does this work?How does this work? struct object { vector<std::unique_ptr<void>> mixins; struct vtable_entry { void* mixin; void* caller; }; vector<vtable_entry> vtable; template <typename Mixin> void add() { mixins.emplace_back(make_unique<Mixin>()); auto info = info_for((Mixin*)nullptr); for(size_t i=0; i<registered_messages.size(); ++ if (info->funcs[i]) vtable[i] = {mixins.back().get(), info->funcs[i]}; } } };
  • 87. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 87/93 How does this work?How does this work? struct object { vector<std::unique_ptr<void>> mixins; struct vtable_entry { void* mixin; void* caller; }; vector<vtable_entry> vtable; template <typename Mixin> void add() { mixins.emplace_back(make_unique<Mixin>()); auto info = info_for((Mixin*)nullptr); for(size_t i=0; i<registered_messages.size(); ++ if (info->funcs[i]) vtable[i] = {mixins.back().get(), info->funcs[i]}; } } };
  • 88. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 88/93 How does this work?How does this work? struct object { vector<std::unique_ptr<void>> mixins; struct vtable_entry { void* mixin; void* caller; }; vector<vtable_entry> vtable; template <typename Mixin> void add() { mixins.emplace_back(make_unique<Mixin>()); auto info = info_for((Mixin*)nullptr); for(size_t i=0; i<registered_messages.size(); ++ if (info->funcs[i]) vtable[i] = {mixins.back().get(), info->funcs[i]}; } } };
  • 89. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 89/93 How does this work?How does this work? struct object { vector<std::unique_ptr<void>> mixins; struct vtable_entry { void* mixin; void* caller; }; vector<vtable_entry> vtable; template <typename Mixin> void add() { mixins.emplace_back(make_unique<Mixin>()); auto info = info_for((Mixin*)nullptr); for(size_t i=0; i<registered_messages.size(); ++ if (info->funcs[i]) vtable[i] = {mixins.back().get(), info->funcs[i]}; } } };
  • 90. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 90/93 How does this work?How does this work? struct object { vector<std::unique_ptr<void>> mixins; struct vtable_entry { void* mixin; void* caller; }; vector<vtable_entry> vtable; template <typename Mixin> void add() { mixins.emplace_back(make_unique<Mixin>()); auto info = info_for((Mixin*)nullptr); for(size_t i=0; i<registered_messages.size(); ++ if (info->funcs[i]) vtable[i] = {mixins.back().get(), info->funcs[i]}; } } };
  • 91. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 91/93 How does this work?How does this work? void moveTo(object& o, int target) { auto& entry = o.vtable[moveTo_id]; auto caller = reintepret_cast<void(*)(void*, int)>(e caller(entry.mixin, target); }
  • 92. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 92/93 The beast is back! - Jon Kalb
  • 93. 5/27/2019 Object-Oriented Programming in Modern C++ https://ibob.github.io/slides/oop-in-cpp/index.html?print-pdf#/ 93/93 EndEnd Questions?Questions? Borislav Stanimirov / /ibob.github.io @stanimirovb Link to these slides: Slides license http://ibob.github.io/slides/oop-in-cpp/ Creative Commons By 3.0