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 created by Andrei Alexandrescu and developed alongside his book "Modern C++ Design."
The C++ community can benefit from a library that provides a robust framework for implementing 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 to a minimum.
- The library prioritizes "Multiplicative excellence," focusing on achieving nuanced, specialized designs through the combination of concise, abstract behavior modules (policies).
- Loki emphasizes strategic rather than tactical approaches, prioritizing design and architectural components over low-level 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, easy to understand and implement, effective both individually and in combination, and highly useful in real-world projects.
Loki incorporates several valuable design patterns, including:
- Factory
- Abstract Factory
- Visitor
- Singleton
It also makes use of several useful idioms:
- 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 learn about design patterns through a well-crafted library while making the most of the features introduced in recent C++ standards.
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. These include:
- SmartPointer
- Tuple
- NullType
- Typelist
- static_check
Therefore, the first step is to remove these classes and replace their uses throughout the rest of the source code.
In the near future, we plan to release a series of posts about this incredible library to help developers modernize it.
