C++

Smart Pointers in C++ are elegant abstractions for managing dynamic memory safely, avoiding dangling pointers and preventing leaks. While std::unique_ptr and std::shared_ptr are well understood and widely used, std::weak_ptr often demands a deeper dive to use correctly. In this article, I will attempt to explain what it is and where it is useful. Some basics […]

Clean interface design is a crucial aspect of software engineering since it enables code flexibility, reuse, and maintainability. Developers who prefer an object-oriented approach typically rely on inheritance to define the interface and thus establish type relationships. While this can lead to a good design if approached carefully, detractors of OOP point out that this […]

Recently I came across a nice article by Jose Crespo, where the author stresses that the future of programming revolves around the application of math concepts such as Functor, Monads, Folds, etc. In addition, he argues that familiarity with C/C++ is essential in this modern AI age. The author goes through a toy example that uses […]

In my earlier article, I had briefly described the REST server I wanted to build for Krishnamurti Padhdhati system of astrology. After a long time I have managed to complete the implementation and it is now ready for deployment. In this article, I will go over some of its features with the hope it will […]

Title: C++ Initialization Story – A Guide Through All Initialization Options and Related C++ Areas Author: Bartłomiej Filipek Publisher: Leanpub Year: 2023 Can you believe that there is a language where “initialization” itself involves many subtleties and a whole book can be devoted to this topic? Yes, modern C++ is such a language! While many […]

The constinit specifier, introduced in C++20, is applied to static variables (global and local static) and thread local variables, with the requirement that they either have a zero initialization or they are initialized with a compile-time constant expression. Here is our first example: Line 17 declares a global constinit variable, initialized with a constant value. […]

“If consteval” is useful in the context of calling a consteval function from within a constexpr function. A consteval function can only be invoked in a constant expression and hence is evaluated at compile-time. On the other hand, a constexpr function may be invoked in a constant expression or non-constant expression. If invoked in a […]

The type trait “std::is_scoped_enum<T>::value” was introduced in C++23 to check whether the type “T” is a scoped enum type. Another way to use this is std::is_scoped_enum_v<T>. Before getting into this trait in detail, let us briefly recap the differences between unscoped and scoped enums. Unscoped Enums Unscoped enums are the old-style enums. Look at the […]

The ability to enumerate stack frames at runtime is one of the interesting features introduced in C++23. This is made possible through the <stacktrace> header. The interface is quite simple. Here is a piece of code showing how to use the library. There are 4 functions and here is the call chain: The “dumpStackTrace()” function […]

I had written about std::optional<> in an earlier article. C++23 introduces std::expected<> as an interesting extension to std::optional<>. Whereas std::optional<> contains a value or none at all, std::expected<> contains a value or an error code associated with it. This gives better control to the caller in terms of handling the outcome of the function call. […]
Recent Comments