Fake Run-Time Selection of Template Arguments in C++

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.

[1]  Jerry P. Draayer,et al.  Ab initio symplectic no-core shell model , 2008 .

[2]  Katherine Yelick,et al.  OSKI: A library of automatically tuned sparse matrix kernels , 2005 .

[3]  David Abrahams,et al.  C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ In-Depth Series) , 2004 .

[4]  Michael A. Heroux,et al.  Trilinos users guide. , 2003 .

[5]  Stephen Prata C++ Primer Plus (Fourth Edition) , 2001 .

[6]  Andrei Alexandrescu,et al.  Modern C++ design: generic programming and design patterns applied , 2001 .

[7]  Lee R. Nackman,et al.  Scientific and Engineering C++: An Introduction with Advanc , 1995, IEEE Computational Science and Engineering.

[8]  Douglas Gregor,et al.  C++ Templates: The Complete Guide , 2002 .

[9]  R. F. Boisvert,et al.  The Matrix Market Exchange Formats: Initial Design | NIST , 1996 .

[10]  Bjarne Stroustrup,et al.  The C++ Programming Language: Special Edition , 2000 .

[11]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[12]  Jaakko Järvi,et al.  Efficient run-time dispatching in generic programming with minimal code bloat , 2011, Sci. Comput. Program..

[13]  Tomás Dytrych,et al.  Evidence for symplectic symmetry in Ab initio no-core shell model results for light nuclei. , 2007, Physical review letters.

[14]  Jerry P. Draayer,et al.  Dominant role of symplectic symmetry in ab initio no-core shell model results for light nuclei , 2007 .

[15]  Davide Di Gennaro Advanced C++ Metaprogramming , 2011 .

[16]  Timothy A. Davis,et al.  The university of Florida sparse matrix collection , 2011, TOMS.

[17]  Nicholas Nethercote,et al.  Valgrind: a framework for heavyweight dynamic binary instrumentation , 2007, PLDI '07.