Should you opt to delve into modern C++ design with a background in Object-Oriented Programming (OOP), consider starting your journey with the Loki library.
Loki is a C++ software library authored by Andrei Alexandrescu, developed alongside his book “Modern C++ Design.”
In the C++ community, there’s a need for a library that provides a robust framework for design patterns. Loki stands out as a strong contender for such a role. Therefore, modernizing Loki and incorporating as many widely used design patterns as possible would greatly benefit C++ developers.
The library extensively utilizes C++ template metaprogramming to implement several widely used constructs, including typelists, functors, singletons, smart pointers, object factories, visitors, and multimethods.
Here is the motivation behind the library’s design, as explained by the author:
- Loki allows users to selectively use only the features they need, with each component functioning independently of the others.
- Embracing the principle that “Small is beautiful,” Loki keeps its internal dependencies minimal.
- The library prioritizes “Multiplicative excellence,” focusing on achieving nuanced, specialized designs through the combination of concise, abstract behavior modules (policies).
- Loki emphasizes strategic over tactical approaches, prioritizing design and architectural components over granular details.
- Being a collection of design patterns rather than a monolithic design, Loki minimizes assumptions about its operating environment and offers flexibility through well-defined extension points for integrating default decisions.
- Loki is tailored for modern compilers, striving for code clarity within the standards of C++ without compromising for less capable compilers.
- Its components are designed to be compact, straightforward to comprehend and implement, effective whether used alone or in combination, and significantly beneficial for projects.
Loki incorporates several valuable design patterns, including:
- Factory
- Abstract Factory
- Visitor
- Singleton
Numerous idioms have been utilized for this purpose:
- policy based design
- Multiple dispatcher
- Pimpl
- Printf (a typesafe printf replacement)
- Ordered static object creation
- Scope guard pointer
- Small Object Allocator
- Smart pointer
- Compile time check
A detailed explanation of the idioms mentioned can be found in this insightful resource.
CoderGears has initiated a contest to update this remarkable library. The primary objective is to understand design patterns through a well-crafted library and to leverage the new features introduced in recent C++ standards as much as possible.
For developers eager to undertake its modernization, the initial query to address is: What is the first step in this refactoring process?
Loki was created prior to the introduction of newer C++ standards, meaning that some of the classes originally designed and developed by the author now have equivalents in these recent standards. We can list:
- SmartPointer
- Tuple
- NullType
- Typelist
- static_check
Therefore, the initial step involves eliminating these classes and substituting their usage throughout the remaining source code.
In the near future, we plan to release a series of posts about this incredible library to assist developers in its modernization.