multiple arguments. The variadic alternative for the case study is presented in the
subsequent ’Solution’ section. The case study intentionally avoids looking at the
std::tuple implementation as many examples already exist for this elsewhere.
The code for this section can be found in appendix ’6.1 Case Study Templates’.
2.1 Case Study: Policy-based ’Lifeform’ Library Class
Imagine a programmer is creating animal management systems for clients such as
zoos, veterinary practices, labs, or shelters. The programmer knows that these
clients care for many forms of life, but they do not know specific details about
the inhabitants. It is known however, that each client has a fixed specialism such
as a lab that only tracks rats & flies, or a shelter looking after only dogs & cats.
It’s decided therefore that the programmer will create a common template library
that can be re-used to match each client’s specifications.
The use of templates for this purpose will allow unused library code to be ig-
nored by compilers, resulting in no run-time overheads and smaller source code
files, as overloading won’t need to be done manually. It will allow the programmer
to streamline their own implementations in the future or to share their library
with clients for them to customize themselves. In both cases, they can easily ask
each client to specify what they want from their system. The following types of
policy were specified for the Lifeform class:
• TaxonomyPolicy - specifying the kingdom, phylum, genus, class, order, fam-
ily, and species.
• MovementPolicy - specifying methods and descriptions for movement such
as bipedal, quadrupedal, flight, slithering, swimming, gliding, ciliary, et. al.
• AppearancePolicy - specifying physical attributes such as width, height,
length, circumference, and counts for items like arms, legs, eyes, ears, and
the like.
• FeedingPolicy - specifying what the animal consumes or eats. Herbivorous,
carnivourous, omnivourous, photosynthesizing, etc.
• ReproductionPolicy - specifying how the lifeform reproduces (through eggs,
babies, pollination, mitosis, or otherwise) as well as the strategy (intermit-
2