C++20 Coroutine: Under The Hood

A coroutine is one of the major feature introduced with the C++20 standard apart from Module, Ranges & Concept. And you see how happy I am to unfold it. I already set the baseline on this topic with my previous article that Coroutine in C Language, where we saw, how suspension-resumption of execution works! With this article “C++20 Coroutine: Under The Hood”, we will see how compiler creates magic & standard library helps it with basic infrastructure making C++20 coroutine more sophisticated(yet complex) & scalable/customizable....

May 9, 2021 · 16 min · 3199 words · Vishal Chovatiya

Coroutine in C Language

It’s been quite a while that I haven’t published anything on my blog. But that’s due to the job change. I hope you understand that it has never been easy to re-settle in a new environment with new people while maintaining a steep technical learning curve. It takes time to tune yourself accordingly. Anyways, I wrote on “Coroutine in C Language” as a pre-pend to my upcoming post on C++20 Coroutine....

April 24, 2021 · 11 min · 2254 words · Vishal Chovatiya

Mastering C++: Books | Courses | Tools | Tutorials | Blogs | Communities

Do not get carried away with tittle Mastering C++. This is a never-ending journey. Because ISOCPP is releasing the baby elephants every three years. With the standard covering almost 1500 pages currently, C++ is not the simplest language to learn and master. I have spent quite enough time in the industry. But still feel imposter sometimes. It’s been quite a while I was thinking of sharing my Modern C++ journey. Although, I am sharing the knowledge piece-by-piece through such articles....

July 20, 2020 · 7 min · 1466 words · Vishal Chovatiya

Regex C++

Regular expressions (or regex in short) is a much-hated & underrated topic so far with Modern C++. But at the same time, correct use of regex can spare you writing many lines of code. If you have spent quite enough time in the industry. And not knowing regex then you are missing out on 20-30% productivity. In that case, I highly recommend you to learn regex, as it is one-time investment(something similar to learn once, write anywhere philosophy)....

July 16, 2020 · 11 min · 2235 words · Vishal Chovatiya

Using std::map Wisely With Modern C++

std::map and its siblings(std::multimap, std::unordered_map/multimap) used to be my favourite containers when I was doing competitive programming. In fact, I still like them(though using less frequently nowadays). And with Modern C++, we now have more reasons to use std::map. That’s why I have decided to address this topic by writing an article summarizing these new features. So, without much gibberish, let’s dive-in directly. std::map::contains(C++20) std::map::contains member function is a good step towards code expressiveness....

July 8, 2020 · 10 min · 2120 words · Vishal Chovatiya

CRTP C++ Examples

Curiously Recurring Template Pattern(CRTP) in C++ is definitely a powerful technique & static alternative to virtual functions. But at the same time, learning it may seem a bit weird at first. If you are like me who struggled to grasp anything in one go. Then this article might help you to provide a thought process on where CRTP fits in day-to-day coding. And, if you are an Embedded Programmer, you may run into CRTP more often....

July 3, 2020 · 13 min · 2755 words · Vishal Chovatiya

C++ Template: A Quick UpToDate Look(C++11/14/17/20)

I know, it’s been a while since the last time I published something newbies-friendly on my blog. The main reason is that most of my readers are either experienced devs or from C background having modest C++ encounter. But while programming in C++ you need a completely different mindset as both C & C++ belongs to different programming paradigm. And I always strive to show them a better way of doing things in C++....

May 17, 2020 · 23 min · 4754 words · Vishal Chovatiya

Variadic Template C++: Implementing Unsophisticated Tuple

From C++11, std::tuple is an incredible expansion to Modern C++, that offers a fixed-size col­lec­tion of het­ero­ge­neous values. Un­for­tu­nately, tu­ples can be somewhat dubious to manage in a conventional fash­ion. But, subsequently released C++ stan­dard in­tro­duced a few fea­tures & helpers that greatly re­duce the nec­es­sary boil­er­plate. So, in this article, I will explain the variadic template in C++ with the help of unsophisticated tuple implementation. And also walks you through a tricky part of tuple i....

May 17, 2020 · 10 min · 2001 words · Vishal Chovatiya

Watchdog Timer(WDT) & Window Watchdog Timer(WWDT)

In the embedded systems/SoCs, Watchdog Timer(WDT) is the basic, subtle and essential circuit/ic. No matter, how good you write your firmware/software. There are always unexpected situations like your program may stick in an infinite loop, hung somewhere or hardware burn-out/failure. To combat these unexpected situations, we need some circuitry that keeps monitoring the main system/application and in case of unexpected events, it restarts the system. Even the windows-like operating system use the watchdog timer....

May 17, 2020 · 5 min · 1023 words · Vishal Chovatiya

Double Dispatch in C++: Recover Original Type of the Object Pointed by Base Class Pointer

Double Dispatch in C++ is a mechanism that dispatches a function call to different concrete functions depending on the runtime types of two objects involved in the call. In more simple words, its function calling using two different virtual tables of respective two objects. I know this sounds cryptic, but don’t worry I will come to double dispatch solution after trying most of the naive solution so that you will come away with the full understanding of concept without having needless confusions....

April 11, 2020 · 11 min · 2184 words · Vishal Chovatiya

Liskov's Substitution Principle in C++ | SOLID as a Rock

So you know how to code in general, understand the object-oriented programming, learned C++, and completed at least one Software Development Course (if you’re not there yet, these articles aren’t for you). You can write software easily if you know at least one programming language, but is your code any good? Could it be done any better? Is it clean (and what on earth does that mean)? Is your architecture any good?...

April 7, 2020 · 7 min · 1387 words · Vishal Chovatiya

Open Closed Principle in C++ | SOLID as a Rock

This is the second part of a five-part article series about SOLID as Rock design principle. The SOLID design principles, when combined together, make it easy for a programmer to craft software that is easy to maintain, reuse & extend. Open-Closed Principle(OCP) is the second principle in this series which I will discuss here with minimalistic example in Modern C++ along with its benefits & generic guideline. By the way, If you haven’t gone through my previous articles on design principles, then below is the quick links:...

April 7, 2020 · 8 min · 1596 words · Vishal Chovatiya

Single Responsibility Principle in C++ | SOLID as a Rock

This article is the first part of a five-part series about SOLID as Rock design principle series. The SOLID design principles focus on developing software that is easy to maintainable, reusable & extendable. In this article, we will see an example of the Single Responsibility Principle in C++ along with its benefits & generic guideline. By the way, If you want to directly jumps to other design principles, then below is the quick links:...

April 7, 2020 · 6 min · 1105 words · Vishal Chovatiya

What Is Design Pattern?

After hitting a certain level of experience & spending quite enough time in the industry, I have realised the importance of designing/architecting system & software. So I have started looking into system/software design & got to know nothing can better start than a Design Pattern. And the first thing I have done is googling “What is Design Pattern?” Hence got the idea of this article. But as someone without a computer science background(I am from electronics background), learning them was a struggle....

April 7, 2020 · 8 min · 1576 words · Vishal Chovatiya

Builder Design Pattern in Modern C++

In software engineering, Creational Design Patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic or ordinary form of object creation could result in design problems or added complexity to the design. Builder Design Pattern in C++ solves this specific problem by separating the construction of a complex object from its representation. By the way, If you haven’t check out my other articles on Creational Design Patterns, then here is the list:...

April 6, 2020 · 9 min · 1802 words · Vishal Chovatiya

Dependency Inversion Principle in C++ | SOLID as a Rock

Dependency Inversion Principle in C++ is the fifth & last design principle of a series SOLID as a Rock design principles. The SOLID design principles focus on developing software that is easy to maintainable, reusable & extendable. In this article, we will see an example code with the flaw & correct it with help of DIP. We will also see guideline & benefits of DIP in closure of the article....

April 6, 2020 · 6 min · 1203 words · Vishal Chovatiya

Factory Design Pattern in Modern C++

In software engineering, Creational Design Patterns deal with object creation mechanisms, i.e. try to create objects in a manner suitable to the situation. In addition to this basic or ordinary form of object creation could result in design problems or added complexity to the design. Factory Design Pattern in C++ helps to mitigate this issue by creating objects using separate methods or polymorphic classes. By the way, If you haven’t check out my other articles on Creational Design Patterns, then here is the list:...

April 6, 2020 · 10 min · 2040 words · Vishal Chovatiya

Interface Segregation Principle in C++ | SOLID as a Rock

Interface Segregation Principle in C++ is the fourth & by far the simplest design principle of a series SOLID as a Rock design principles. The SOLID design principles focus on developing software that is easy to maintainable, reusable & extendable. In this article, we will see a code violating ISP, a solution to the same code, guideline & benefits of ISP. By the way, If you haven’t gone through my previous articles on design principles, then below is the quick links:...

April 6, 2020 · 5 min · 1014 words · Vishal Chovatiya

Prototype Design Pattern in Modern C++

Prototype Design Pattern is a Creational Design Pattern that helps in the prototyping(creating/copying cheaply) of an object using separate methods or polymorphic classes. You can consider the prototype as a template of an object before the actual object is constructed. In this article of the Creational Design Patterns, we’re going to take a look at why we need a Prototype Design Pattern in C++ i.e. motivation, prototype factory & leveraging prototype design pattern to implement virtual copy constructor....

April 6, 2020 · 9 min · 1805 words · Vishal Chovatiya

Singleton Design Pattern in Modern C++

In software engineering, Creational Design Patterns deal with object creation mechanisms, i.e. try to create objects in a manner suitable to the situation. The basic or ordinary form of object creation could result in design problems or added complexity to the design. In this article of the Creational Design Patterns, we’re going to take a look at the much-hated & commonly asked design pattern in a programming interview. That is Singleton Design Pattern in Modern C++ which criticizes for its extensibility & testability....

April 6, 2020 · 9 min · 1810 words · Vishal Chovatiya

Adapter Design Pattern in Modern C++

In software engineering, Structural Design Patterns deal with the relationship between object & classes i.e. how object & classes interact or build a relationship in a manner suitable to the situation. The structural design patterns simplify the structure by identifying relationships. In this article of the Structural Design Patterns, we’re going to take a look at Adapter Design Pattern in Modern C++ which used to convert the interface of an existing class into another interface that client/API-user expect....

April 5, 2020 · 7 min · 1317 words · Vishal Chovatiya

Bridge Design Pattern in Modern C++

Bridge Design Pattern is a Structural Design Pattern used to decouple a class into two parts – abstraction and it’s implementation – so that both can be developed independently. This promotes the loose coupling between class abstraction & its implementation. You get this decoupling by adding one more level of indirection i.e. an interface which acts as a bridge between your original class & functionality. Insulation is another name of Bridge Design Pattern in C++ world....

April 5, 2020 · 8 min · 1646 words · Vishal Chovatiya

Composite Design Pattern in Modern C++

GoF describes the Composite Design Pattern as “Compose objects into a tree structure to represent part-whole hierarchies. Composite lets the client treat individual objects and compositions of objects uniformly”. This seems over-complicated to me. So, I would not go into tree-leaf kind of jargon. Rather I directly saw you 2 or 3 different ways to implement Composite Design Pattern in Modern C++. But in simple words, the Composite Design Pattern is a Structural Design Pattern with a goal to treat the group of objects in the same manner as a single object....

April 5, 2020 · 8 min · 1683 words · Vishal Chovatiya

Decorator Design Pattern in Modern C++

In software engineering, Structural Design Patterns deal with the relationship between object & classes i.e. how object & classes interact or build a relationship in a manner suitable to the situation. The Structural Design Patterns simplify the structure by identifying relationships. In this article of the Structural Design Patterns, we’re going to take a look at the not so complex yet subtle design pattern that is Decorator Design Pattern in Modern C++ due to its extensibility & testability....

April 5, 2020 · 8 min · 1611 words · Vishal Chovatiya

Facade Design Pattern in Modern C++

Facade Design Pattern is a Structural Design Pattern used to provide a unified interface to a complex system. It is same as Facade in building architecture, a Facade is an object that serves as a front-facing interface masking a more complex underlying system. A Facade Design Pattern in C++ can: Improve the readability & usability of a software library by masking interaction with more complex components by providing a single simplified API....

April 5, 2020 · 5 min · 920 words · Vishal Chovatiya

Flyweight Design Pattern in Modern C++

Flyweight Design Pattern is a Structural Design Pattern that concerned with space optimization. It is a technique to minimizes memory footprint by sharing or avoiding redundancy as much as possible with other similar objects. Flyweight Design Pattern in Modern C++ is often used in a situation where object count is higher which uses an unacceptable amount of memory. Often some parts of these objects can be shared & kept in common data structures that can be used by multiple objects....

April 5, 2020 · 6 min · 1098 words · Vishal Chovatiya

Proxy Design Pattern in Modern C++

In software engineering, Structural Design Patterns deal with the relationship between objects i.e. how objects/classes interact or build a relationship in a manner suitable to the situation. The Structural Design Patterns simplify the structure by identifying relationships. In this article of the Structural Design Patterns, we’re going to take a look at Proxy Design Pattern in C++ which dictates the way you access the object. If you haven’t check out other Structural Design Patterns, then here is the list:...

April 5, 2020 · 7 min · 1378 words · Vishal Chovatiya

Chain of Responsibility Design Pattern in Modern C++

Chain of Responsibility is a Behavioural Design Pattern that provides facility to propagate event/request/command/query to the chain of loosely coupled objects. Chain of Responsibility Design Pattern in Modern C++ lets you pass requests along a chain of handlers & upon receiving a request, each handler decides either to process the request or to forward it to the next handler in the chain. By the way, If you haven’t check out my other articles on Behavioural Design Patterns, then here is the list:...

April 3, 2020 · 7 min · 1337 words · Vishal Chovatiya

Command Design Pattern in Modern C++

In software engineering, Behavioural Design Patterns deal with the assignment of responsibilities between objects which in turn make the interaction between the objects easy & loosely coupled. In this article of the Behavioural Design Patterns, we’re going to take a look at Command Design Pattern in Modern C++ which encapsulate all the details related to operation into a separate object. Command Design Pattern is widely used in sophisticated software. In fact, you might be using it every day without even knowing that....

April 3, 2020 · 7 min · 1415 words · Vishal Chovatiya

Interpreter Design Pattern in Modern C++

Interpreter Design Pattern is a Behavioural Design Pattern which is a component that processes structured text data by turning it into separate lexical tokens(lexing) and then interpreting sequences of tokens(parsing). In this article, we will see the Interpreter Design Pattern in Modern C++. By the way, If you haven’t check out my other articles on Behavioural Design Patterns, then here is the list: Chain of responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor The code snippets you see throughout this series of articles are simplified not sophisticated....

April 3, 2020 · 6 min · 1254 words · Vishal Chovatiya

Iterator Design Pattern in Modern C++

Iterator Design Pattern in Modern C++ is a heavily used pattern i.e. provides facility to traverse data containers sophistically. For simplicity, you can consider a pointer moving across an array, but the real magic comes when you get to the next element of a container, in that case, you need not know anything about how the container is constructed(like sequential(not necessarily be contiguous), associative or hashed). This is handled by the iterator....

April 3, 2020 · 10 min · 1918 words · Vishal Chovatiya

Mediator Design Pattern in Modern C++

In software engineering, Behavioural Design Patterns deal with the assignment of responsibilities between objects & encapsulating behaviour in an object to delegate requests. In this article of the Behavioural Design Patterns, we’re going to take a look at Mediator Design Pattern in Modern C++. And the motivation behind the Mediator Design Pattern is to provide proper communication between components by letting the components be aware(or unaware also, depending upon use case) of each other’s presence or absence in the system....

April 3, 2020 · 6 min · 1071 words · Vishal Chovatiya

Memento Design Pattern in Modern C++

Memento Design Pattern in Modern C++ is a very straight forward Behavioural Design Pattern. The motivation behind using the Memento Design Pattern is to keep some sort of token which then allows you to restore an object to a particular state. This is particularly useful if you have a system with medieval components i.e. an object or indeed a set of objects goes through a set of changes. By the way, If you haven’t check out my other articles on Behavioural Design Patterns, then here is the list:...

April 3, 2020 · 5 min · 1039 words · Vishal Chovatiya

Observer Design Pattern in Modern C++

The Observer Design Pattern is a type of Behavioural Design Pattern that use to get information when certain events happen i.e. basically one component want information about something happening in the other component. And that can a lot of things like a field changes to a particular value or you want to information when the object does a particular thing, etc. Observer Design Pattern in Modern C++ enables you to create subscription mechanism to notify multiple objects about events that happen to the object they’re observing....

April 3, 2020 · 5 min · 1026 words · Vishal Chovatiya

Double Dispatch : Visitor Design Pattern in Modern C++

In software engineering, Behavioural Design Patterns deal with the assignment of responsibilities between objects. That in turn, make the interaction between the objects easy & loosely coupled. In this article of the design pattern series, we’re going to take a look at Visitor Design Pattern in Modern C++ which is also known as a classic technique for recovering lost type information(using Double Dispatch[TODO]). Visitor Design Pattern is used to perform an operation on a group of similar kind of objects or hierarchy....

April 2, 2020 · 10 min · 2108 words · Vishal Chovatiya

State Design Pattern in Modern C++

A State Design Pattern is a type of Behavioural Design Pattern that defines objects behaviour(defined as a state) based on some event happens. And that can be the internal or external event. For example, if you design an ATM machine using the State Design Pattern, the external event could be someone inserted debit/credit card & internal event could be a user timeout. So in nutshell, the State Design Pattern in Modern C++ is a systematic way to implement certain behaviour on a particular event considering the context....

April 2, 2020 · 11 min · 2304 words · Vishal Chovatiya

Strategy Design Pattern in Modern C++

In software engineering, Behavioural Design Patterns deal with the assignment of responsibilities between objects which in turn make the interaction between the objects easy & loosely coupled. In this article of the Behavioural Design Pattern series, we’re going to take a look at Strategy Design Pattern in Modern C++. It allows you to partially specify the behaviour of the class and then augment it later on. This pattern is also known as policy in many programming languages including especially in the C++ language....

April 2, 2020 · 6 min · 1179 words · Vishal Chovatiya

Template Method Design Pattern in Modern C++

In software engineering, Behavioural Design Patterns deal with the assignment of responsibilities between objects. And encapsulating behaviour in an object to delegate requests. The Behavioural Design Patterns make the interaction between the objects easy & loosely coupled. In this article of the design pattern series, we’re going to take a look at Template Method Design Pattern in Modern C++. It allows us to define the skeleton of the algorithm in the base class with concrete implementations defined in derived classes....

April 2, 2020 · 6 min · 1097 words · Vishal Chovatiya

What Exactly nullptr Is in C++?

The answer to “What exactly nullptr is in C++?” would be a piece of cake for experienced C++ eyes & for those who are aware of Modern C++ i.e. keyword. But nullptr is more than just a keyword in C++ & to explain that, I have written this article. But before jump-into it, we will see issues with NULL & then we’ll dive into the unsophisticated implementation of nullptr & some use-cases of nullptr....

November 30, 2019 · 7 min · 1325 words · Vishal Chovatiya

7 Advance C++ Concepts & Idiom Examples You Should Know

So I have started updating myself with Modern C++ a while ago & since my post 21 new features of Modern C++ to use in your project & All about lambda function in C++ was popular I decided to write about advance C++ concepts & idioms which I have learned from this wikibook & course. There are many other advance C++ concepts & idioms as well but I consider these 7 as “should-know”....

November 16, 2019 · 16 min · 3358 words · Vishal Chovatiya

C++ Exception Handling Best Practices: 7 Things To Know

Exception handling in C++ is a well-unschooled topic if you observe initial stages of the learning curve. There are numerous tutorials available online on exception handling in C++. But few explains what you should not do & intricacies around it. So here I am to bridge the gap & show you some intricacies, from where & why you should not throw an exception and C++ exception handling best practices. Along with some newer features introduced for exception handling in Modern C++ with example....

November 3, 2019 · 14 min · 2938 words · Vishal Chovatiya

21 New Features of Modern C++ to Use in Your Project

So, you came across the Modern C++ & overwhelmed by its features in terms of performance, convenience & code expressiveness. But in a dilemma that how you can spot where you can enforce Modern C++ features in your day to day coding job. No worries, here we will see 21 new features of Modern C++ you can use in your project. C++ community releasing new standards more frequently than iPhone releases....

October 13, 2019 · 13 min · 2675 words · Vishal Chovatiya

All About Lambda Function in C++(From C++11 to C++20)

Lambda function is quite an intuitive & widely loved feature introduced in C++11. And, there are tons of articles & tutorials already available on the topic. But, there are very few or none of them touched upon things like IIFE, types of lambda and newer updates on lambda by subsequent standard releases. So, I got the opportunity to fill the blank. I will start this article with what is lambda function!...

September 19, 2019 · 8 min · 1670 words · Vishal Chovatiya

How C Program Converts Into Assembly!

In an earlier article, we have seen C runtime: before starting main & How C program stored in RAM memory. Here we will see “How C program converts into assembly?” and different aspect of its working at the machine level. A Bit About Functions Stack Frames During function code execution, a new stack frame is created in stack memory to allow access to function parameters and local variables. The direction of stack frame growth totally depends on compiler ABI which is out of our scope for this article....

September 16, 2019 · 6 min · 1149 words · Vishal Chovatiya

How C Program Stored in Ram Memory!

When you run any C-program, its executable image loaded into RAM of computer in an organized manner which called process address space or memory layout of C program. Here I have tried to show you the same thing in two parts . In the 1st part i.e. “Overview”, we will see segment-wise overview & in 2nd part i.e. “Example”, we’ll see How C program stored in RAM memory? with example....

September 16, 2019 · 9 min · 1715 words · Vishal Chovatiya

Default Handlers in C: weak_alias

Default Handlers in C: weak_alias function tells the linker that new is to be a weak alias for old. That is, this definition of new is a weak symbol. If there is no other definition of a symbol called new, this old definition stands. Might seems alien to you first, so go through a below example & read again. Definition of weak_alias is as follows : 1 2 #define weak_alias(old, new) \ extern __typeof(old) new __attribute__((weak, alias(#old))) If there is another (non-weak) definition of new then that non-weak(i....

September 15, 2019 · 2 min · 256 words · Vishal Chovatiya

How Floating-Point No Is Stored in Memory?

This article is just a simplification of the IEEE 754 standard. Here, we will see how floating-point no stored in memory, floating-point exceptions/rounding, etc. But if you will want to find more authoritative sources then go for What Every Computer Scientist Should Know About Floating-Point Arithmetic https://en.wikipedia.org/wiki/IEEE_754-1985 https://en.wikipedia.org/wiki/Floating_point. Floating-point numbers stored by encoding significand & the exponent (along with a sign bit) Above line contains 2-3 abstract terms & I think you will unable to understand the above line until you read further....

September 15, 2019 · 7 min · 1324 words · Vishal Chovatiya

How to Install and Configure VNC Server on Linux!

In the early days of my career, I used to work on Linux machines remotely. In those days, I was not knowing about SSH & all and people around me was using Putty as it was very easy & simple. Open source as well. You just have to enter IP & Port and you would get command-line access to remote machine. here, we will discuss “how to install and configure VNC server on Linux?...

September 15, 2019 · 3 min · 468 words · Vishal Chovatiya

Lvalue Rvalue and Their References With Example in C++

This topic might be a piece of cake for every experienced C++ veteran. But I remember back in the days when I was a novice & introducing myself with Modern C++, I was really irritated by C++ compiler messages saying this is lvalue & that is rvalue kind of jargons. And even if you are not using C++, you may have faced compiler error in C language saying “lvalue required as left operand of assignment”....

September 15, 2019 · 9 min · 1820 words · Vishal Chovatiya

Move Constructor & Assignment Operator With std::shared_ptr

In an earlier article, we have seen how move constructor & move assignment operators helped us in creating our own unique_ptr. Here we will use move constructor & assignment operator to implement unsophisticated shared_ptr. Implementing Our shared_ptr with Move Constructor & Assignment Operator In some cases, we have a requirement where a single resource is represented by multiple pointers. We can not accomplish this by std::unique_ptr. To accomplish this, we can add a new variable to our smart pointer class which keeps track of reference count at the real-time....

September 15, 2019 · 5 min · 913 words · Vishal Chovatiya