Book Image

C++ Reactive Programming

By : Praseed Pai, Peter Abraham
Book Image

C++ Reactive Programming

By: Praseed Pai, Peter Abraham

Overview of this book

Reactive programming is an effective way to build highly responsive applications with an easy-to-maintain code base. This book covers the essential functional reactive concepts that will help you build highly concurrent, event-driven, and asynchronous applications in a simpler and less error-prone way. C++ Reactive Programming begins with a discussion on how event processing was undertaken by different programming systems earlier. After a brisk introduction to modern C++ (C++17), you’ll be taken through language-level concurrency and the lock-free programming model to set the stage for our foray into the Functional Programming model. Following this, you’ll be introduced to RxCpp and its programming model. You’ll be able to gain deep insights into the RxCpp library, which facilitates reactive programming. You’ll learn how to deal with reactive programming using Qt/C++ (for the desktop) and C++ microservices for the Web. By the end of the book, you will be well versed with advanced reactive programming concepts in modern C++ (C++17).
Table of Contents (20 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Flattening the composite for iterative processing


We have already learned that the Visitor pattern has to know the structure of the composite for someone to write an instance of the Visitor interface. This can create an anomaly called abstraction leak. The GoF pattern catalog has a pattern that will help us to navigate the contents of a tree in a structure-agnostic manner. Yes, you might have guessed it correctly: the Iterator pattern is the candidate! For the Iterator to do its job, the composite has to be flattened into a list sequence or Stream. Let's write some code to flatten the expression tree that we modeled in the previous section. Before we write the logic to flatten a Composite, let's create a data structure to store the contents of an AST as a list. Every node in the list has to store either an operator or value, depending upon whether we need to store operators or operands. We describe a data structure called EXPR_ITEM for this purpose:

//////////////////////////// 
// A enum...