These are the slides from my ACCU 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=JGYxOieiZnY. All my other talks can be found here: https://train-it.eu/resources.
---
This short talk presents how easy it is to replace some cases of dynamic polymorphism with std::variant. During the lecture, we will analyze and compare a few implementations of the same simple Finite State Machine. It turns up that variant-based code is not only much faster but also it gives us the opportunity to define our interfaces and program flow much better. The talk will end up with the discussion of pros and cons of each approach and will try to give guidelines on when to use them.
Implementing Physical Units Library for C++Mateusz Pusz
These are the slides from my 4Developers 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=O1vlFZcaMKo. All my other talks can be found here: https://train-it.eu/resources.
---
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces, and a full power of using concepts to constrain template types.
Effective replacement of dynamic polymorphism with std::variantMateusz Pusz
These are the slides from my CppCon 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=gKbORJtnVu8. All my other talks can be found here: https://train-it.eu/resources.
---
This short talk presents how easy it is to replace some cases of dynamic polymorphism with std::variant. During the lecture, we will analyze and compare 2 implementations of the same simple Finite State Machine. It turns up that variant-based code is not only much faster but also it gives us the opportunity to define our interfaces and program flow much better. The talk will end up with the discussion of pros and cons of each approach and will try to give guidelines on when to use them.
Model-Based Optimization for Effective and Reliable Decision-MakingBob Fourer
Optimization originated as an advanced mathematical technique, but it has become an accessible and widely used decision-making tool. A key factor in the spread of successful optimization applications has been the adoption of a model-based approach: A domain expert or operations analyst focuses on modeling the problem of interest, while the computation of a solution is left to general-purpose, off-the-shelf solvers; powerful yet intuitive modeling software manages the difficulties of translating between the human modeler’s formulation and the solver software’s needs. This talk introduces model-based optimization by contrasting it to a method-based approach that relies on customized implementation of rules and algorithms. Model-based implementations are illustrated using the AMPL modeling language and popular solvers. The presentation concludes by surveying the variety of modeling languages and solvers available for model-based optimization today.
Implementing Physical Units Library for C++. Mateusz Pusz.CoreHard Spring 2019corehard_by
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces and the full power of using concepts to constrain template types.
Implementing a Physical Units Library for C++Mateusz Pusz
These are the slides from my keynote talk on C++ on CoreHard Spring 2019. You can find the recording here: https://www.youtube.com/watch?v=hcgL8QBmh2I. All my other talks can be found here: https://train-it.eu/resources.
---
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces and the full power of using concepts to constrain template types.
In Network Computing Prototype Using P4 at KSC/KREONET 2019Kentaro Ebisawa
Case Study of P4 applying to CAN (Control Area Network) data pre-processing using FPGA + Netcope P4 compiler.
Presented at KSC / KREONET WORKSHOP 2019 | DAY 1 Session 1: SDN/NFV/P4
http://www.ksc2019.re.kr/
Implementing Physical Units Library for C++Mateusz Pusz
These are the slides from my 4Developers 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=O1vlFZcaMKo. All my other talks can be found here: https://train-it.eu/resources.
---
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces, and a full power of using concepts to constrain template types.
Effective replacement of dynamic polymorphism with std::variantMateusz Pusz
These are the slides from my CppCon 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=gKbORJtnVu8. All my other talks can be found here: https://train-it.eu/resources.
---
This short talk presents how easy it is to replace some cases of dynamic polymorphism with std::variant. During the lecture, we will analyze and compare 2 implementations of the same simple Finite State Machine. It turns up that variant-based code is not only much faster but also it gives us the opportunity to define our interfaces and program flow much better. The talk will end up with the discussion of pros and cons of each approach and will try to give guidelines on when to use them.
Model-Based Optimization for Effective and Reliable Decision-MakingBob Fourer
Optimization originated as an advanced mathematical technique, but it has become an accessible and widely used decision-making tool. A key factor in the spread of successful optimization applications has been the adoption of a model-based approach: A domain expert or operations analyst focuses on modeling the problem of interest, while the computation of a solution is left to general-purpose, off-the-shelf solvers; powerful yet intuitive modeling software manages the difficulties of translating between the human modeler’s formulation and the solver software’s needs. This talk introduces model-based optimization by contrasting it to a method-based approach that relies on customized implementation of rules and algorithms. Model-based implementations are illustrated using the AMPL modeling language and popular solvers. The presentation concludes by surveying the variety of modeling languages and solvers available for model-based optimization today.
Implementing Physical Units Library for C++. Mateusz Pusz.CoreHard Spring 2019corehard_by
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces and the full power of using concepts to constrain template types.
Implementing a Physical Units Library for C++Mateusz Pusz
These are the slides from my keynote talk on C++ on CoreHard Spring 2019. You can find the recording here: https://www.youtube.com/watch?v=hcgL8QBmh2I. All my other talks can be found here: https://train-it.eu/resources.
---
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces and the full power of using concepts to constrain template types.
In Network Computing Prototype Using P4 at KSC/KREONET 2019Kentaro Ebisawa
Case Study of P4 applying to CAN (Control Area Network) data pre-processing using FPGA + Netcope P4 compiler.
Presented at KSC / KREONET WORKSHOP 2019 | DAY 1 Session 1: SDN/NFV/P4
http://www.ksc2019.re.kr/
APEX Interactive Grid API Essentials: The Stuff You Will Really UseKaren Cannell
This presentation covers the latest APEX 18 Interactive Grid features then focuses on the newly-documents Grid JavaScript APIs. The key point is that documented means supported. The session covers some simple examples of use of the Grid APIs for common applications. These lay the foundation for more complex use of the Grid and other documented APIs for real life business rules. The accompanying application contains the examples discussed in the presentation.
An overview of IBM Business Continuity and Disaster Recovery solutions, including backups to tape, snapshots, object storage and remote mirroring. Presented in Orlando, FL IBM Technical University.
Characteristics of Remote Persistent Memory – Performance, Capacity, or Local...inside-BigData.com
In this deck from the 2019 OpenFabrics Workshop in Austin, Paul Grun from Cray presents: Characteristics of Remote Persistent Memory – Performance, Capacity, or Locality. Which One(s)?
Persistent Memory exhibits several interesting characteristics including persistence, capacity and others. These (sometimes)competing characteristics may require system and server architects to make tradeoffs in system architecture. A sometimes overlooked tradeoff is in the locality of the persistent memory, i.e. locally-attached persistent memory versus remote(or fabric-attached) persistent memory. In this session, we explore some of those tradeoffs and take an early look at the emerging use cases for Remote Persistent Memory and how those may impact network architecture and API design.
Watch the video: https://wp.me/p3RLHQ-jZR
Learn more: https://www.openfabrics.org/2019-workshop-agenda-and-abstracts/
Sign up for our insideHPC Newsletter: http://insidehpc.com/newsletter
Backend Cloud Storage Access in Video StreamingRufael Mekuria
Presentation about optimizing access of backend storage in cloud video streaming deployments, given at Packet Video 2018 in Amsterdam the Netherlands, joint work with Christina Kylili TU Delft
CP Optimizer is a generic system, largely based on CP, to model and solve real-world combinatorial optimization problems with a particular focus on planning and scheduling applications. It provides an algebraic language with simple mathematical concepts (such as intervals, sequences or functions) to capture the temporal dimension of planning and scheduling problems in a combinatorial optimization framework. CP Optimizer implements a model-and-run paradigm that vastly reduces the burden on the user to understand CP or scheduling algorithms: modeling is by far the most important. The automatic search integrates a large panel of techniques from Artificial Intelligence (constraint programming, temporal reasoning, learning, ...) and Operations Research (mathematical programming, graph algorithms, local search, ...) into an exact algorithm that provides good performance out of the box and is continuously improving. This tutorial gives an overview of CP Optimizer for planning and scheduling: typical applications, modeling concepts with examples, ingredients of the automatic search, tools and performance.
Introduction to HPC Programming Models - EUDAT Summer School (Stefano Markidi...EUDAT
Stefano will give an introduction to the most common and used programming models for performing parallel I/O on supercomputers. He will first give a broad overview of parallel APIs for programming I/O on supercomputers. He will then introduce MPI I/O, one of the most used programming interfaces for parallel I/O, presenting its basic concepts, providing programming examples and guidelines for achieving high performance I/O on supercomputers.
Visit: https://www.eudat.eu/eudat-summer-school
Machine Learning Meets Quantitative Planning: Enabling Self-Adaptation in Aut...Pooyan Jamshidi
Modern cyber-physical systems (e.g., robotics systems) are typically composed of physical and software components, the characteristics of which are likely to change over time. Assumptions about parts of the system made at design time may not hold at run time, especially when a system is deployed for long periods (e.g., over decades). Self-adaptation is designed to find reconfigurations of systems to handle such run-time inconsistencies. Planners can be used to find and enact optimal reconfigurations in such an evolving context. However, for systems that are highly configurable, such planning becomes intractable due to the size of the adaptation space. To overcome this challenge, in this paper we explore an approach that (a) uses machine learning to find Pareto-optimal configurations without needing to explore every configuration and (b) restricts the search space to such configurations to make planning tractable. We explore this in the context of robot missions that need to consider task timeliness and energy consumption. An independent evaluation shows that our approach results in high-quality adaptation plans in uncertain and adversarial environments.
Paper: https://arxiv.org/abs/1903.03920
Collective Mind: a collaborative curation tool for program optimizationGrigori Fursin
Designing and optimizing applications becomes increasingly tedious, time consuming, ad-hoc and error prone due to ever changing and complex hardware and software stack. At the same time, it becomes difficult or even impossible to validate, reproduce and extend many proposed optimization and auto-tuning techniques from numerous publications. One of the main reasons is a lack of common and practical way to preserve, systematize and reuse available knowledge and artifacts including developments, optimizations and experimental data.
In this talk, I will present modular, extensible, python-based Collective Mind framework and web-based schema-free repository
(c-mind.org) that I developed at first to systematize my own research and experimentation on machine learning based program optimization and compiler design. This infrastructure can be customized to preserve, describe, share and reproduce whole experimental setups including benchmarks, data sets, libraries, tools, predictive models and optimization information with related JSON-based meta-data. I will also present and discuss positive and negative feedback during several recent academic and industrial usages of this framework to systematize benchmarking and program optimization, and to initiate new publication model where experimental results and related research artifacts are shared, reproduced and validated by the community. In a long term, I hope that such approach and collective knowledge will eventually help us to squeeze maximum performance from computer systems while minimizing energy, development time and other costs.
CK: from ad hoc computer engineering to collaborative and reproducible data s...Grigori Fursin
Designing novel computer systems and optimizing their software is becoming too tedious, ad hoc, time consuming and error prone due to enormous number of available design and optimization choices. Empirical autotuning combined with run-time adaptation and machine learning has been demonstrating some potential to address above challenges for several decades but is still far from the widespread production. The main reasons include unbearably long exploration and training times, ever changing tools and their interfaces, lack of a common experimental methodology, lack of diverse and representative benchmarks, and lack of unified mechanisms for knowledge building and exchange apart from publications where reproducibility and reusability of results is often not even considered.
I will present our community-driven solution to above problems based on our open-source Collective Knowledge technology (CK) that can gradually organize, exchange and reuse knowledge and experience in computer engineering. CK helps share various artifacts (benchmarks, data sets, libraries, tools) as unified, reusable and Python-based components with JSON meta description via GITHUB. Researchers can then quickly prototype and crowdsource various experimental workflows such as performance and energy autotuning, design space exploration and run-time adaptation. At the same time, CK continuously analyzes and extrapolates all collected knowledge using powerful data science techniques to automatically model computer systems' behavior, predict better optimizations or hardware configurations, and eventually enable faster, more power efficient, reliable and self-tuning software and hardware. Furthermore, CK can record any unexpected behavior in a reproducible way and expose it to an interdisciplinary community to find missing features and improve models. Live demo of our approach is available at http://cknowledge.org/repo .
Free Lunch is Over: Why is C++ so Important in the Modern World?Mateusz Pusz
"Don’t pay for what you don’t use" and "Don't leave room for a language below C++ (except assembler)" are the C++ design and evolution priorities that have stuck with us since the beginning of the programming language. CPU clock frequencies stopped growing more than 10 years ago, and since that time, our processor cores are no longer accelerating. Moreover, the demand for power savings is higher than ever for both small factor devices, like mobile phones, and for huge factor server farms. In the domains where each CPU cycle counts, C++ is the fastest and the most robust solution on the market. C++ programming language is evolving faster now than ever before — and EPAM is an active contributor to this transformation. This talk will briefly summarize the history of C++, describe the benefits of the programming language, highlight the business domains where its usage is essential, and provide some insights on the future of the language and its standardization process.
A Physical Units Library for the Next C++Mateusz Pusz
These are the slides from my CppCon 2020 talk. You can find the recording here: https://www.youtube.com/watch?v=7dExYGSOJzo. All my other talks can be found here: https://train-it.eu/resources.
---
During CppCon 2019 Mateusz provided an overview of current solutions on the market as well as challenges of implementing a modern C++ physical units library. This year's talk will focus on 'mp-units', the library that was developed by Mateusz and contributors, and which is proposed for C++ standardization. During the tutorial, we will get familiar with the building blocks of the library's framework and its most important concepts. Numerous code examples will present how to use and solve real-life problems with the library. The audience will learn how easy it is to extend it with new units, dimensions, or even whole new systems of quantities. Last but not least Mateusz will provide a fair comparison of how well this library performs in comparison to other products on the market.
More Related Content
Similar to Effective replacement of dynamic polymorphism with std::variant
APEX Interactive Grid API Essentials: The Stuff You Will Really UseKaren Cannell
This presentation covers the latest APEX 18 Interactive Grid features then focuses on the newly-documents Grid JavaScript APIs. The key point is that documented means supported. The session covers some simple examples of use of the Grid APIs for common applications. These lay the foundation for more complex use of the Grid and other documented APIs for real life business rules. The accompanying application contains the examples discussed in the presentation.
An overview of IBM Business Continuity and Disaster Recovery solutions, including backups to tape, snapshots, object storage and remote mirroring. Presented in Orlando, FL IBM Technical University.
Characteristics of Remote Persistent Memory – Performance, Capacity, or Local...inside-BigData.com
In this deck from the 2019 OpenFabrics Workshop in Austin, Paul Grun from Cray presents: Characteristics of Remote Persistent Memory – Performance, Capacity, or Locality. Which One(s)?
Persistent Memory exhibits several interesting characteristics including persistence, capacity and others. These (sometimes)competing characteristics may require system and server architects to make tradeoffs in system architecture. A sometimes overlooked tradeoff is in the locality of the persistent memory, i.e. locally-attached persistent memory versus remote(or fabric-attached) persistent memory. In this session, we explore some of those tradeoffs and take an early look at the emerging use cases for Remote Persistent Memory and how those may impact network architecture and API design.
Watch the video: https://wp.me/p3RLHQ-jZR
Learn more: https://www.openfabrics.org/2019-workshop-agenda-and-abstracts/
Sign up for our insideHPC Newsletter: http://insidehpc.com/newsletter
Backend Cloud Storage Access in Video StreamingRufael Mekuria
Presentation about optimizing access of backend storage in cloud video streaming deployments, given at Packet Video 2018 in Amsterdam the Netherlands, joint work with Christina Kylili TU Delft
CP Optimizer is a generic system, largely based on CP, to model and solve real-world combinatorial optimization problems with a particular focus on planning and scheduling applications. It provides an algebraic language with simple mathematical concepts (such as intervals, sequences or functions) to capture the temporal dimension of planning and scheduling problems in a combinatorial optimization framework. CP Optimizer implements a model-and-run paradigm that vastly reduces the burden on the user to understand CP or scheduling algorithms: modeling is by far the most important. The automatic search integrates a large panel of techniques from Artificial Intelligence (constraint programming, temporal reasoning, learning, ...) and Operations Research (mathematical programming, graph algorithms, local search, ...) into an exact algorithm that provides good performance out of the box and is continuously improving. This tutorial gives an overview of CP Optimizer for planning and scheduling: typical applications, modeling concepts with examples, ingredients of the automatic search, tools and performance.
Introduction to HPC Programming Models - EUDAT Summer School (Stefano Markidi...EUDAT
Stefano will give an introduction to the most common and used programming models for performing parallel I/O on supercomputers. He will first give a broad overview of parallel APIs for programming I/O on supercomputers. He will then introduce MPI I/O, one of the most used programming interfaces for parallel I/O, presenting its basic concepts, providing programming examples and guidelines for achieving high performance I/O on supercomputers.
Visit: https://www.eudat.eu/eudat-summer-school
Machine Learning Meets Quantitative Planning: Enabling Self-Adaptation in Aut...Pooyan Jamshidi
Modern cyber-physical systems (e.g., robotics systems) are typically composed of physical and software components, the characteristics of which are likely to change over time. Assumptions about parts of the system made at design time may not hold at run time, especially when a system is deployed for long periods (e.g., over decades). Self-adaptation is designed to find reconfigurations of systems to handle such run-time inconsistencies. Planners can be used to find and enact optimal reconfigurations in such an evolving context. However, for systems that are highly configurable, such planning becomes intractable due to the size of the adaptation space. To overcome this challenge, in this paper we explore an approach that (a) uses machine learning to find Pareto-optimal configurations without needing to explore every configuration and (b) restricts the search space to such configurations to make planning tractable. We explore this in the context of robot missions that need to consider task timeliness and energy consumption. An independent evaluation shows that our approach results in high-quality adaptation plans in uncertain and adversarial environments.
Paper: https://arxiv.org/abs/1903.03920
Collective Mind: a collaborative curation tool for program optimizationGrigori Fursin
Designing and optimizing applications becomes increasingly tedious, time consuming, ad-hoc and error prone due to ever changing and complex hardware and software stack. At the same time, it becomes difficult or even impossible to validate, reproduce and extend many proposed optimization and auto-tuning techniques from numerous publications. One of the main reasons is a lack of common and practical way to preserve, systematize and reuse available knowledge and artifacts including developments, optimizations and experimental data.
In this talk, I will present modular, extensible, python-based Collective Mind framework and web-based schema-free repository
(c-mind.org) that I developed at first to systematize my own research and experimentation on machine learning based program optimization and compiler design. This infrastructure can be customized to preserve, describe, share and reproduce whole experimental setups including benchmarks, data sets, libraries, tools, predictive models and optimization information with related JSON-based meta-data. I will also present and discuss positive and negative feedback during several recent academic and industrial usages of this framework to systematize benchmarking and program optimization, and to initiate new publication model where experimental results and related research artifacts are shared, reproduced and validated by the community. In a long term, I hope that such approach and collective knowledge will eventually help us to squeeze maximum performance from computer systems while minimizing energy, development time and other costs.
CK: from ad hoc computer engineering to collaborative and reproducible data s...Grigori Fursin
Designing novel computer systems and optimizing their software is becoming too tedious, ad hoc, time consuming and error prone due to enormous number of available design and optimization choices. Empirical autotuning combined with run-time adaptation and machine learning has been demonstrating some potential to address above challenges for several decades but is still far from the widespread production. The main reasons include unbearably long exploration and training times, ever changing tools and their interfaces, lack of a common experimental methodology, lack of diverse and representative benchmarks, and lack of unified mechanisms for knowledge building and exchange apart from publications where reproducibility and reusability of results is often not even considered.
I will present our community-driven solution to above problems based on our open-source Collective Knowledge technology (CK) that can gradually organize, exchange and reuse knowledge and experience in computer engineering. CK helps share various artifacts (benchmarks, data sets, libraries, tools) as unified, reusable and Python-based components with JSON meta description via GITHUB. Researchers can then quickly prototype and crowdsource various experimental workflows such as performance and energy autotuning, design space exploration and run-time adaptation. At the same time, CK continuously analyzes and extrapolates all collected knowledge using powerful data science techniques to automatically model computer systems' behavior, predict better optimizations or hardware configurations, and eventually enable faster, more power efficient, reliable and self-tuning software and hardware. Furthermore, CK can record any unexpected behavior in a reproducible way and expose it to an interdisciplinary community to find missing features and improve models. Live demo of our approach is available at http://cknowledge.org/repo .
Free Lunch is Over: Why is C++ so Important in the Modern World?Mateusz Pusz
"Don’t pay for what you don’t use" and "Don't leave room for a language below C++ (except assembler)" are the C++ design and evolution priorities that have stuck with us since the beginning of the programming language. CPU clock frequencies stopped growing more than 10 years ago, and since that time, our processor cores are no longer accelerating. Moreover, the demand for power savings is higher than ever for both small factor devices, like mobile phones, and for huge factor server farms. In the domains where each CPU cycle counts, C++ is the fastest and the most robust solution on the market. C++ programming language is evolving faster now than ever before — and EPAM is an active contributor to this transformation. This talk will briefly summarize the history of C++, describe the benefits of the programming language, highlight the business domains where its usage is essential, and provide some insights on the future of the language and its standardization process.
A Physical Units Library for the Next C++Mateusz Pusz
These are the slides from my CppCon 2020 talk. You can find the recording here: https://www.youtube.com/watch?v=7dExYGSOJzo. All my other talks can be found here: https://train-it.eu/resources.
---
During CppCon 2019 Mateusz provided an overview of current solutions on the market as well as challenges of implementing a modern C++ physical units library. This year's talk will focus on 'mp-units', the library that was developed by Mateusz and contributors, and which is proposed for C++ standardization. During the tutorial, we will get familiar with the building blocks of the library's framework and its most important concepts. Numerous code examples will present how to use and solve real-life problems with the library. The audience will learn how easy it is to extend it with new units, dimensions, or even whole new systems of quantities. Last but not least Mateusz will provide a fair comparison of how well this library performs in comparison to other products on the market.
These are the slides from my keynote talk on C++ on CoreHard Autumn 2019. You can find the recording here: https://www.youtube.com/watch?v=nqf53MlnMpo. All my other talks can be found here: https://train-it.eu/resources.
---
That talk will present the C++ world seen from Low Latency domain. The world where no dynamic allocations are welcomed, C++ exceptions are nearly not used, where STL containers are often not enough, and where developers often need to go deep down to assembly level to verify if the code really does its best.
Rethinking the Way We do Templates in C++Mateusz Pusz
These are the slides from my CppCon 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=oNBnYhLxlTU. All my other talks can be found here: https://train-it.eu/resources.
---
Template metaprogramming is hard. In case it is hard only for the library implementer then it is not that bad. The problem arises when it also affects the users of this library.
This talk is summarizing my experience and thoughts gathered during the implementation of the Physical Units Library for C++. The way we do template metaprogramming now results with inscrutable compile-time errors and really long type names observed while debugging our code. That is mostly caused by aliasing class template specializations of non-trivial metaprogramming interface designs. Compilation times of such code also leave a lot of room for improvement, and the practices we chose to use in the Standard Library are often suboptimal. Taking into account the Rule of Chiel while designing templated code makes a huge difference in the compile times. This talk presents a few simple examples (including the practices from the C++ Standard Library) of achieving the same goal in different ways and provides benchmark results of time needed to compile such source code.
These are the slides from my talk on C++ London meetup. You can find the recording here: https://www.youtube.com/watch?v=HsC1EoFjf8U. All my other talks can be found here: https://train-it.eu/resources.
---
C++ is the fastest programming language in the world, and it leaves no room for other languages below it (except assembler). That is why it gets more attention now than ever before. As a result, we observe an increasing speed of C++ language evolution. C++11 was a game changer, but is now considered an "old" language already. C++14 & 17 provided many improvements that allow us to write portable, safer, and faster code in a shorter time. The resulting source code is easier to reason about and maintain. Moreover, C++20 is coming soon, and it is going to be a game changer again.
In my talk, I provide a few typical legacy code examples that most of us write every day. I describe how those samples evolve with the changes introduced in the each C++ language release from C++11 up to the major groundbreaking features of the upcoming C++20. During the talk, the audience will learn how much easier, more robust, and safer is the code written using modern tools that we get with every new C++ release.
C++ Concepts and Ranges - How to use them?Mateusz Pusz
These are the slides from my Meeting C++ 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=pe05ZWdh0N0. All my other talks can be found here: https://train-it.eu/resources.
---
The most of the Concepts TS and Ranges TS is merged into the C++20 standard draft document. The talk will present a current design of those features and will provide suggestions on how to use them in our source code. That presentation is meant to inspire discussion on how should we use those long-awaited features while building tools and the C++ Standard Library.
Git, CMake, Conan - How to ship and reuse our C++ projects?Mateusz Pusz
These are the slides from my CppCon 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=S4QSKLXdTtA. All my other talks can be found here: https://train-it.eu/resources.
---
Git and CMake are already established standards in our community. However, it is uncommon to see them being used in an efficient way. As a result, many C++ projects have big problems with either importing other dependencies or making themselves easy to import by others. It gets even worse when we need to build many different configurations of our package on one machine.
That presentation lists and addresses the problems of build system and packaging that we have with large, multi-platform, C++ projects that often have many external and internal dependencies. The talk will present how proper use of CMake and Conan package manager can address those use cases. It will also describe current issues with the cooperation of those tools.
If you've attended or seen my talk at C++Now 2018, that time you can expect much more information on Conan and package creation using that tool. I will also describe how the integration of CMake and Conan changed over the last few months.
These are the slides from my C++Now 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=y7PBciQp0B8. All my other talks can be found here: https://train-it.eu/resources.
---
Presentation of features already voted into C++20 Standard Draft in Toronto, Albuquerque, and Jacksonville ISO C++ Committee Meetings as well as the overview of other really promising proposals that have high chances to arrive in C++20.
Pointless Pointers - How to make our interfaces efficient?Mateusz Pusz
These are the slides from my code::dive 2017 talk. You can find the recording here: https://www.youtube.com/watch?v=qrifyjQW9gA. All my other talks can be found here: https://train-it.eu/resources.
---
C++ is not C. C++ developers too often forget about that. The effects are often disastrous. nullptr dereferences, buffer overflows, resource leaks are the problems often seen in C++ applications bug trackers. Does it have to be like that? The talk presents a few simple rules tested in production that will make most of those issues go away and never appear again in the C++ software. Interested? Come and see :-)
These are the slides from my 4Developers 2017 talk. You can find the recording here: https://www.youtube.com/watch?v=pU0VRMqM5vs. All my other talks can be found here: https://train-it.eu/resources.
---
That talk will present the C++ world seen from Low Latency domain. The world where no dynamic allocations are welcomed, C++ exceptions are nearly not used, where STL containers are often not enough, and where developers often need to go deep down to assembly level to verify if the code really does its best.
These are the slides from my code::dive 2016 talk. You can find the recording here: https://www.youtube.com/watch?v=yCfFt061SU4. All my other talks can be found here: https://train-it.eu/resources.
---
Writing fast C++ applications is a really complex subject. It often turns out that deep but isolated knowledge of ISO C++ standard and algorithmic complexity of operations does not guarantee the success. Often the bottleneck of our applications happens to be the performance of computer’s memory or its wrong usage by our code. The lack of knowledge in that subject can ruin all our ambitions to create high performance implementation.
std::shared_ptr<T> - (not so) Smart hammer for every pointy nailMateusz Pusz
These are the slides from my code::dive 2016 talk. You can find the recording here: https://www.youtube.com/watch?v=hHQS-Q7aMzg. All my other talks can be found here: https://train-it.eu/resources.
---
C++ rule of thumb is “you do not pay for what you do not use”. However, it turns out that this is not the case for some of the utilities from the C++ Standard Library. The key example here is the favorite tool of many developers – std::shared_ptr. The talk will describe the problems related to it in detail. It will also try to answer the question how it was possible to avoid them.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Effective replacement of dynamic polymorphism with std::variant
1. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 1/108
Mateusz Pusz
April 12, 2019
E ective replacement of dynamic
polymorphism with
std::variant
2. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 2/108
Why?
3. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 3/108
• Time required to perform some action or to produce some result
• Measured in units of time like hours, minutes, seconds, nanoseconds or clock periods
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Why?
LATENCY
3
4. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 4/108
• Time required to perform some action or to produce some result
• Measured in units of time like hours, minutes, seconds, nanoseconds or clock periods
• In capital markets, the use of algorithmic trading to react to market events faster than the competition
to increase profitability of trades
• Many use cases where predictability of latency in message delivery is just as important, if not more
important than achieving a low average latency
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Why?
LATENCY
LOW LATENCY
3
5. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 5/108
• In Low Latency system we care a lot about
WCET (Worst Case Execution Time)
• In order to limit WCET we should limit the
usage of specific C++ language features
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
How NOT to develop software that have predictable
performance?
4
6. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 6/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
7. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 7/108
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
8. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 8/108
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
• Throwing exceptions on a likely code path
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
9. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 9/108
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
• Throwing exceptions on a likely code path
• Dynamic polymorphism
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
10. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 10/108
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
• Throwing exceptions on a likely code path
• Dynamic polymorphism
• Multiple inheritance
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
11. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 11/108
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
• Throwing exceptions on a likely code path
• Dynamic polymorphism
• Multiple inheritance
• RTTI
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
12. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 12/108
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
• Throwing exceptions on a likely code path
• Dynamic polymorphism
• Multiple inheritance
• RTTI
• Dynamic memory allocations
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
5
13. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 13/108
• Dynamic polymorphism
• Dynamic memory allocations
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Things to avoid on the fast path
• C++ tools that trade performance for usability (e.g. std::shared_ptr, std::function)
• Throwing exceptions on a likely code path
• Multiple inheritance
• RTTI
6
14. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 14/108
How?
15. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 15/108
class base : noncopyable {
public:
virtual ~base() = default;
virtual void foo() = 0;
};
class x : public base {
public:
void foo() override;
};
class y : public base {
public:
void foo() override;
};
std::unique_ptr<base> b = std::make_unique<x>();
b->foo();
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
How?
DYNAMIC POLYMORPHISM
8
16. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 16/108
class base : noncopyable {
public:
virtual ~base() = default;
virtual void foo() = 0;
};
class x : public base {
public:
void foo() override;
};
class y : public base {
public:
void foo() override;
};
std::unique_ptr<base> b = std::make_unique<x>();
b->foo();
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
How?
DYNAMIC POLYMORPHISM
8
17. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 17/108
class base : noncopyable {
public:
virtual ~base() = default;
virtual void foo() = 0;
};
class x : public base {
public:
void foo() override;
};
class y : public base {
public:
void foo() override;
};
std::unique_ptr<base> b = std::make_unique<x>();
b->foo();
struct x { void foo(); };
struct y { void foo(); };
std::variant<x, y> b;
std::visit([](auto&& v){ v.foo(); }, b);
• Shorter
• Faster
• Value semantics
• Works on unrelated classes
• More flexible thanks to duck typing
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
How?
DYNAMIC POLYMORPHISM VARIANT
8
18. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 18/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
THE END
T H A N K Y O U !
9
19. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 19/108
Bonus slides
20. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 20/108
Abstract machine that can be in exactly one of a finite number of
states at any given time.
-- Wikipedia
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Finite State Machine
11
21. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 21/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Finite State Machine
12
22. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 22/108
• State changes to another in a response to
some external inputs called events
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Finite State Machine
12
23. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 23/108
• State changes to another in a response to
some external inputs called events
• The change from one state to another is
called a transition
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Finite State Machine
12
24. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 24/108
• State changes to another in a response to
some external inputs called events
• The change from one state to another is
called a transition
• A FSM is defined by
– a list of states
– its initial state
– the conditions for each transition
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Finite State Machine
12
25. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 25/108
Single dynamic dispatch
CASE #1
26. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 26/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Class diagram
14
27. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 27/108
template<typename Event>
class state : noncopyable {
public:
virtual ~state() = default;
virtual std::unique_ptr<state> on_event(Event) = 0;
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
15
28. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 28/108
template<typename Event>
class state : noncopyable {
public:
virtual ~state() = default;
virtual std::unique_ptr<state> on_event(Event) = 0;
};
template<typename Event>
class fsm {
std::unique_ptr<state<Event>> state_;
public:
explicit fsm(std::unique_ptr<state<Event>> state) : state_(std::move(state)) {}
void dispatch(Event e)
{
auto new_state = state_->on_event(e);
if(new_state)
state_ = std::move(new_state);
}
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
15
29. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 29/108
template<typename Event>
class state : noncopyable {
public:
virtual ~state() = default;
virtual std::unique_ptr<state> on_event(Event) = 0;
};
template<typename Event>
class fsm {
std::unique_ptr<state<Event>> state_;
public:
explicit fsm(std::unique_ptr<state<Event>> state) : state_(std::move(state)) {}
void dispatch(Event e)
{
auto new_state = state_->on_event(e);
if(new_state)
state_ = std::move(new_state);
}
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
16
30. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 30/108
class connection_fsm : public fsm<event> {
public:
connection_fsm():
fsm<event>(std::make_unique<state_idle>()) {}
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Connection FSM
17
31. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 31/108
class connection_fsm : public fsm<event> {
public:
connection_fsm():
fsm<event>(std::make_unique<state_idle>()) {}
};
using s = state<event>;
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Connection FSM
17
32. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 32/108
class connection_fsm : public fsm<event> {
public:
connection_fsm():
fsm<event>(std::make_unique<state_idle>()) {}
};
using s = state<event>;
class state_idle final : public s {
public:
std::unique_ptr<s> on_event(event e) override;
};
class state_connecting final : public s {
static constexpr int n_max = 3;
int n = 0;
public:
std::unique_ptr<s> on_event(event e) override;
};
class state_connected final : public s {
public:
std::unique_ptr<s> on_event(event e) override;
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Connection FSM
17
33. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 33/108
std::unique_ptr<s> state_idle::on_event(event e)
{
}
std::unique_ptr<s> state_connecting::on_event(event e)
{
}
std::unique_ptr<s> state_connected::on_event(event e)
{
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Transitions
18
34. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 34/108
std::unique_ptr<s> state_idle::on_event(event e)
{
if(e == event::connect)
return std::make_unique<state_connecting>();
return nullptr;
}
std::unique_ptr<s> state_connecting::on_event(event e)
{
}
std::unique_ptr<s> state_connected::on_event(event e)
{
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Transitions
18
35. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 35/108
std::unique_ptr<s> state_idle::on_event(event e)
{
if(e == event::connect)
return std::make_unique<state_connecting>();
return nullptr;
}
std::unique_ptr<s> state_connecting::on_event(event e)
{
switch(e) {
case event::connected:
return std::make_unique<state_connected>();
case event::timeout:
return ++n < n_max ?
nullptr : std::make_unique<state_idle>();
default:
return nullptr;
}
}
std::unique_ptr<s> state_connected::on_event(event e)
{
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Transitions
18
37. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 37/108
std::unique_ptr<s> state_idle::on_event(event e)
{
if(e == event::connect)
return std::make_unique<state_connecting>();
return nullptr;
}
std::unique_ptr<s> state_connecting::on_event(event e)
{
switch(e) {
case event::connected:
return std::make_unique<state_connected>();
case event::timeout:
return ++n < n_max ?
nullptr : std::make_unique<state_idle>();
default:
return nullptr;
}
}
std::unique_ptr<s> state_connected::on_event(event e)
{
if(e == event::disconnect)
return std::make_unique<state_idle>();
return nullptr;
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
The slow part
19
38. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 38/108
• Fold expressions come handy ;-)
template<typename Fsm, typename... Events>
void dispatch(Fsm& fsm, Events... events)
{
(fsm.dispatch(events), ...);
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Testing transitions
20
39. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 39/108
• Fold expressions come handy ;-)
template<typename Fsm, typename... Events>
void dispatch(Fsm& fsm, Events... events)
{
(fsm.dispatch(events), ...);
}
• Simple message flow
connection_fsm fsm;
dispatch(fsm, event::connect, event::timeout, event::connected, event::disconnect);
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Testing transitions
20
40. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 40/108
• Open to new alternatives
– new derived types may be added by clients at any point of time (long a er base class
implementation is finished)
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
21
41. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 41/108
• Open to new alternatives
– new derived types may be added by clients at any point of time (long a er base class
implementation is finished)
• Closed to new operations
– clients cannot add new operations to dynamic dispatch
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
21
42. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 42/108
• Open to new alternatives
– new derived types may be added by clients at any point of time (long a er base class
implementation is finished)
• Closed to new operations
– clients cannot add new operations to dynamic dispatch
• Multi-level
– many levels of inheritance possible
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
21
43. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 43/108
• Open to new alternatives
– new derived types may be added by clients at any point of time (long a er base class
implementation is finished)
• Closed to new operations
– clients cannot add new operations to dynamic dispatch
• Multi-level
– many levels of inheritance possible
• Object Oriented
– whole framework is based on objects
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Single dynamic dispatch
21
44. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 44/108
Double dynamic dispatch
CASE #2
45. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 45/108
class event : noncopyable {
public:
virtual ~event() = default;
};
class event_connect final : public event {
std::string_view address_;
public:
explicit event_connect(std::string_view address): address_(address) {}
std::string_view address() const { return address_; }
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
What if we want our events to pass data?
23
46. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 46/108
class event : noncopyable {
public:
virtual ~event() = default;
};
class event_connect final : public event {
std::string_view address_;
public:
explicit event_connect(std::string_view address): address_(address) {}
std::string_view address() const { return address_; }
};
std::unique_ptr<state> state_idle::on_event(const event& e)
{
if(auto ptr = dynamic_cast<const event_connect*>(&e)) { /* ... */ }
else { /* ... */ }
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
What if we want our events to pass data?
23
47. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 47/108
class event : noncopyable {
public:
virtual ~event() = default;
};
class event_connect final : public event {
std::string_view address_;
public:
explicit event_connect(std::string_view address): address_(address) {}
std::string_view address() const { return address_; }
};
std::unique_ptr<state> state_idle::on_event(const event& e)
{
if(auto ptr = dynamic_cast<const event_connect*>(&e)) { /* ... */ }
else { /* ... */ }
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
What if we want our events to pass data?
A really bad idea :-(
23
48. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 48/108
Special form of multiple dispatch, and a mechanism that
dispatches a function call to di erent concrete functions
depending on the runtime types of two objects involved in the call
-- Wikipedia
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Double dispatch (aka Visitor Pattern)
24
49. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 49/108
template<typename State>
struct event : private noncopyable {
virtual ~event() = default;
virtual std::unique_ptr<State> dispatch(State& s) const = 0;
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Double dispatch (aka Visitor Pattern)
25
53. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 53/108
template<typename State>
struct event : private noncopyable {
virtual ~event() = default;
virtual std::unique_ptr<State> dispatch(State& s) const = 0;
};
class state : noncopyable {
public:
virtual ~state() = default;
virtual std::unique_ptr<state> on_event(const event_connect&) { return nullptr; }
virtual std::unique_ptr<state> on_event(const event_connected&) { return nullptr; }
virtual std::unique_ptr<state> on_event(const event_disconnect&) { return nullptr; }
virtual std::unique_ptr<state> on_event(const event_timeout&) { return nullptr; }
};
class state_idle final : public state {
public:
using state::on_event;
std::unique_ptr<state> on_event(const event_connect& e) override
{
return std::make_unique<state_connecting>(std::string(e.address()));
}
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Double dispatch (aka Visitor Pattern)
27
54. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 54/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Class diagram
28
55. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 55/108
template<typename State>
struct event : private noncopyable {
virtual ~event() = default;
virtual std::unique_ptr<State> dispatch(State& s) const = 0;
};
struct event_connect final : public event<state> {
std::unique_ptr<state> dispatch(state& s) const override { return s.on_event(*this); }
// ...
};
struct event_connected final : public event<state> {
std::unique_ptr<state> dispatch(state& s) const override { return s.on_event(*this); }
};
struct event_disconnect final : public event<state> {
std::unique_ptr<state> dispatch(state& s) const override { return s.on_event(*this); }
};
struct event_timeout final : public event<state> {
std::unique_ptr<state> dispatch(state& s) const override { return s.on_event(*this); }
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Curiously Recurring Template Pattern (CRTP)
29
64. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 64/108
std::unique_ptr<state>
state_idle::on_event(const event_connect& e)
{
return std::make_unique<state_connecting>(
std::string{e.address()});
}
std::unique_ptr<state>
state_connecting::on_event(const event_connected&)
{
return std::make_unique<state_connected>();
}
std::unique_ptr<state>
state_connecting::on_event(const event_timeout&)
{
return ++n < n_max ?
nullptr : std::make_unique<state_idle>();
}
std::unique_ptr<state>
state_connected::on_event(const event_disconnect&)
{
return std::make_unique<state_idle>();
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
The slow part
33
65. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 65/108
template<typename Fsm, typename... Events>
void dispatch(Fsm& fsm, const Events&... events)
{
(fsm.dispatch(*events), ...);
}
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Testing transitions
34
66. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 66/108
template<typename Fsm, typename... Events>
void dispatch(Fsm& fsm, const Events&... events)
{
(fsm.dispatch(*events), ...);
}
dispatch(fsm,
std::make_unique<event_connect>("train-it.eu"),
std::make_unique<event_timeout>(),
std::make_unique<event_connected>(),
std::make_unique<event_disconnect>());
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Testing transitions
34
67. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 67/108
template<typename Fsm, typename... Events>
void dispatch(Fsm& fsm, const Events&... events)
{
(fsm.dispatch(*events), ...);
}
dispatch(fsm,
std::make_unique<event_connect>("train-it.eu"),
std::make_unique<event_timeout>(),
std::make_unique<event_connected>(),
std::make_unique<event_disconnect>());
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
The slow part
35
68. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 68/108
• Open to new alternatives
• Closed to new alternatives
– one of class hierarchies fixed at design time and cannot be extended by clients
• Closed to new operations
– clients cannot add new operations to dynamic dispatch
• Multi-level
– many levels of inheritance possible
• Object Oriented
– whole framework is based on objects
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Double dynamic dispatch (aka Visitor Pattern)
36
69. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 69/108
Variant + external transitions
CASE #3
70. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 70/108
struct event_connect { std::string_view address; };
struct event_connected {};
struct event_disconnect {};
struct event_timeout {};
using event = std::variant<event_connect, event_connected, event_disconnect, event_timeout>;
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Events and states
EVENTS
38
71. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 71/108
struct event_connect { std::string_view address; };
struct event_connected {};
struct event_disconnect {};
struct event_timeout {};
using event = std::variant<event_connect, event_connected, event_disconnect, event_timeout>;
struct state_idle {};
struct state_connecting {
static constexpr int n_max = 3;
int n = 0;
std::string address;
};
struct state_connected {};
using state = std::variant<state_idle, state_connecting, state_connected>;
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Events and states
EVENTS
STATES
38
78. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 78/108
template<typename StateVariant, typename EventVariant, typename Transitions>
class fsm {
StateVariant state_;
public:
void dispatch(const EventVariant& event)
{
std::optional<StateVariant> new_state = std::visit(Transitions{}, state_, event);
if(new_state)
state_ = *std::move(new_state);
}
};
using connection_fsm = fsm<state, event, transitions>;
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
FSM engine
40
79. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 79/108
template<typename StateVariant, typename EventVariant, typename Transitions>
class fsm {
StateVariant state_;
public:
void dispatch(const EventVariant& event)
{
std::optional<StateVariant> new_state = std::visit(Transitions{}, state_, event);
if(new_state)
state_ = *std::move(new_state);
}
};
using connection_fsm = fsm<state, event, transitions>;
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
FSM engine
41
80. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 80/108
template<typename StateVariant, typename EventVariant, typename Transitions>
class fsm {
StateVariant state_;
public:
void dispatch(const EventVariant& event)
{
std::optional<StateVariant> new_state = std::visit(Transitions{}, state_, event);
if(new_state)
state_ = *std::move(new_state);
}
};
using connection_fsm = fsm<state, event, transitions>;
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
FSM engine
42
81. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 81/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Class diagram
43
82. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 82/108
template<typename Fsm, typename... Events>
void dispatch(Fsm& fsm, Events&&... events)
{
(fsm.dispatch(std::forward<Events>(events)), ...);
}
dispatch(fsm,
event_connect{"train-it.eu"},
event_timeout{},
event_connected{},
event_disconnect{});
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Testing transitions
44
83. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 83/108
Variant + transitions in FSM
CASE #4
84. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 84/108
template<typename Derived, typename StateVariant, typename EventVariant>
class fsm {
StateVariant state_;
public:
void dispatch(const EventVariant& event)
{
auto new_state = std::visit(
state_, event);
if(new_state)
state_ = *std::move(new_state);
}
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
FSM engine
46
85. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 85/108
template<typename Derived, typename StateVariant, typename EventVariant>
class fsm {
StateVariant state_;
public:
void dispatch(const EventVariant& event)
{
Derived& child = static_cast<Derived&>(*this);
auto new_state = std::visit(
[&](auto& s, const auto& e) -> std::optional<StateVariant>
{ return child.on_event(s, e); },
state_, event);
if(new_state)
state_ = *std::move(new_state);
}
};
• CRTP again ;-)
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
FSM engine
46
86. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 86/108
template<typename Derived, typename StateVariant>
class fsm {
StateVariant state_;
public:
template<typename Event>
void dispatch(Event&& event)
{
Derived& child = static_cast<Derived&>(*this);
auto new_state = std::visit(
[&](auto& s) -> std::optional<StateVariant>
{ return child.on_event(s, std::forward<Event>(event)); },
state_);
if(new_state)
state_ = *std::move(new_state);
}
};
• Visitation on a StateVariant only
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
FSM engine: dispatch() as an overload set
47
87. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 87/108
class connection_fsm
: public fsm<connection_fsm, state> {
public:
auto on_event(state_idle&,
const event_connect& e)
{ }
auto on_event(state_connecting&,
const event_connected&)
{ }
auto on_event(state_connecting& s,
const event_timeout&)
{
}
auto on_event(state_connected&,
const event_disconnect&)
{ }
template<typename State, typename Event>
auto on_event(State&, const Event&)
{ }
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Transitions de ned by the FSM itself
48
88. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 88/108
class connection_fsm
: public fsm<connection_fsm, state> {
public:
auto on_event(state_idle&,
const event_connect& e)
{ return state_connecting{std::string(e.address)}; }
auto on_event(state_connecting&,
const event_connected&)
{ return state_connected{}; }
auto on_event(state_connecting& s,
const event_timeout&)
{
return ++s.n < state_connecting::n_max ?
std::nullopt : std::optional<state>(state_idle{});
}
auto on_event(state_connected&,
const event_disconnect&)
{ return state_idle{}; }
template<typename State, typename Event>
auto on_event(State&, const Event&)
{ return std::nullopt; }
};
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Transitions de ned by the FSM itself
48
89. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 89/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
Class diagram
49
90. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 90/108
What about performance?
91. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 91/108
CLOSED(Start)
LISTEN/-
CLOSE/-
LISTEN
SYN
RECEIVED
SYN
SENT
CONNECT/ (Step 1 of the 3-way-handshake)SYN
SYN/SYN+ACK(Step 2 of the 3-way-handshake)
unusual event
client/receiver path
server/sender path
RST/-
SYN/SYN+ACK (simultaneous open)
SYN+ACK/ACK
(Step 3 of the 3-way-handshake)
Data exchange occurs
ESTABLISHED
FIN/ACK
ACK/-
CLOSE/-
SEND/SYN
CLOSE/FIN
CLOSE/FIN
CLOSING
TIME WAIT
CLOSED
FIN WAIT 1
FIN WAIT 2
CLOSE WAIT
LAST ACK
CLOSE/FIN
FIN/ACK
FIN+ACK/ACK
ACK/-
FIN/ACK
Timeout
(Go back to start)
Active CLOSE Passive CLOSE
ACK/-
ACK/-
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
TCP state diagram
51
92. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 92/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
TCP FSM Performance
52
93. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 93/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
TCP FSM Performance
52
94. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 94/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
TCP FSM Performance
52
95. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 95/108
Summary
96. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 96/108
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
97. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 97/108
• Open/Closed to new alternatives • Closed to new alternatives
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
98. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 98/108
• Open/Closed to new alternatives
• Closed to new operations
• Closed to new alternatives
• Open to new operations
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
99. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 99/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• Closed to new alternatives
• Open to new operations
• Single level
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
100. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 100/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
101. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 101/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Pointer semantics
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
• Value semantics
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
102. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 102/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Pointer semantics
• Design forced by the implementation details
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
• Value semantics
• Many design choices possible
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
103. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 103/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Pointer semantics
• Design forced by the implementation details
• Forces dynamic memory allocations
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
• Value semantics
• Many design choices possible
• No dynamic memory allocations
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
104. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 104/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Pointer semantics
• Design forced by the implementation details
• Forces dynamic memory allocations
• Strict interfaces
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
• Value semantics
• Many design choices possible
• No dynamic memory allocations
• Duck typing
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
105. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 105/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Pointer semantics
• Design forced by the implementation details
• Forces dynamic memory allocations
• Strict interfaces
• Complex
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
• Value semantics
• Many design choices possible
• No dynamic memory allocations
• Duck typing
• Simple
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
106. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 106/108
• Open/Closed to new alternatives
• Closed to new operations
• Multi-level
• OO
• Pointer semantics
• Design forced by the implementation details
• Forces dynamic memory allocations
• Strict interfaces
• Complex
• Slower
• Closed to new alternatives
• Open to new operations
• Single level
• Functional
• Value semantics
• Many design choices possible
• No dynamic memory allocations
• Duck typing
• Simple
• Faster
ACCU 2019 | E ective replacement of dynamic polymorphism with std::variant
std::variant<Types...> vs inheritance
INHERITANCE VARIANT
54
107. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 107/108
108. 12.04.2019 Effective replacement of dynamic polymorphism with std::variant
file:///C:/repos/cppTrainings/build/out/polymorphism_with_variant/polymorphism_with_variant.html#108 108/108