Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. C++ in Depth Series. Addison-Wesley Professional (2004)
Alexandrescu, A.: Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley Longman Publishing Co., Inc., Boston (2001)
Balay, S., Brown, J., Buschelman, K., Eijkhout, V., Gropp, W.D., Kaushik, D., Knepley, M.G., McInnes, L.C., Smith, B.F., Zhang, H.: PETSc Users Manual. Tech. Rep. ANL-95/11 - Revision 3.2, Argonne National Laboratory (2010)
Barton, J.J., Nackman, L.R.: Scientific and Engineering C++: An Introduction with Advanced Techniques and Examples, 1st edn. Addison-Wesley Longman Publishing Co., Inc., Boston (1994)
Boisvert, R.F., Pozo, R., Remington, K.: The Matrix Market Exchange Formats: Initial Design. Tech. Rep. NISTIR 5935, National Institute of Standards and Technology (December 1996)
Bourdev, L., Jin, H.: Generic Image Library, http://opensource.adobe.com/gil (accessed December 2011)
Bourdev, L., Järvi, J.: Efficient run-time dispatching in generic programming with minimal code bloat. Science of Computer Programming 76(4), 243–257 (2011)
Davis, T.A., Hu, Y.F.: The University of Florida Sparse Matrix Collection. ACM Transactions on Mathematical Software 38(1) (November 2011)
Dytrych, T., Sviratcheva, K.D., Bahri, C., Draayer, J.P., Vary, J.P.: Dominant role of symplectic symmetry in ab initio no-core shell model results for light nuclei. Physical Review C 76(1), 014315 (2007)
Dytrych, T., Sviratcheva, K.D., Bahri, C., Draayer, J.P., Vary, J.P.: Evidence for symplectic symmetry in ab initio no-core shell model results for light nuclei. Physical Review Letters 98, 162503 (2007)
Dytrych, T., Sviratcheva, K.D., Draayer, J.P., Bahri, C., Vary, J.P.: Ab initio symplectic no-core shell model. Journal of Physics G: Nuclear and Particle Physics 35(12), 123101 (2008)
Gennaro, D.D.: Advanced C++ Metaprogramming. CreateSpace (2011)
Guennebaud, G., Jacob, B., et al.: Eigen, version 3.0.1 (2010), http://eigen.tuxfamily.org (accessed July 2011)
Heroux, M.A., Willenbring, J.M.: Trilinos users guide. Tech. Rep. SAND2003-2952, Sandia National Laboratories (2003)
ISO/IEC 14882:2003: Programming languages: C++ (2003)
OpenFOAM User Guide, Version 2.0.0 (2011)
Prata, S.: Primer Plus, 4th edn. Sams, Indianapolis, IN, USA (2001)
Stroustrup, B.: The C++ Programming Language: Special Edition, 3 edn. Addison-Wesley Professional (February 2000), http://www.worldcat.org/isbn/0201700735
The Boost MPL Library, http://www.boost.org/doc/libs/1_48_0/libs/mpl/doc/index.html (accessed December 12, 2012)
The HDF Group. Hierarchical data format version 5 (2000-2010), http://www.hdfgroup.org/HDF5/ (accessed March 27, 2011)
Vandevoorde, D., Josuttis, N.M.: C++ Templates—The Complete Guide. Addison-Wesley (2002)
Vuduc, R., Demmel, J.W., Yelick, K.A.: OSKI: A library of automatically tuned sparse matrix kernels. Journal of Physics: Conference Series 16(1), 521–530 (2005)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2012 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Langr, D., Tvrdík, P., Dytrych, T., Draayer, J.P. (2012). Fake Run-Time Selection of Template Arguments in C++. In: Furia, C.A., Nanz, S. (eds) Objects, Models, Components, Patterns. TOOLS 2012. Lecture Notes in Computer Science, vol 7304. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-30561-0_11
Download citation
DOI: https://doi.org/10.1007/978-3-642-30561-0_11
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-30560-3
Online ISBN: 978-3-642-30561-0
eBook Packages: Computer ScienceComputer Science (R0)