2012 | OriginalPaper | Chapter
Fake Run-Time Selection of Template Arguments in C++
Authors : Daniel Langr, Pavel Tvrdík, Tomáš Dytrych, Jerry P. Draayer
Published in: Objects, Models, Components, Patterns
Publisher: Springer Berlin Heidelberg
Activate our intelligent search to find suitable subject content or patents.
Select sections of text to find matching patents with Artificial Intelligence. powered by
Select sections of text to find additional relevant content using AI-assisted search. powered by
C++ does not support run-time resolution of template type arguments. To circumvent this restriction, we can instantiate a template for all possible combinations of type arguments at compile time and then select the proper instance at run time by evaluation of some provided conditions. However, for templates with multiple type parameters such a solution may easily result in a branching code bloat. We present a template metaprogramming algorithm called
for_id
that allows the user to select the proper template instance at run time with theoretical minimum sustained complexity of the branching code.