View Full Document

7 views

Unformatted text preview:

Typesafe Variable length Function and Template Argument Lists Douglas Gregor Gary Powell Jaakko Ja rvi Document number N1483 03 0066 Date 25 April 2003 Project Programming Language C Evolution Working Group Reply to Douglas Gregor gregod cs rpi edu 1 Introduction This proposal addresses three problems under a unified framework The inability to instantiate class and function templates with an arbitrarily long list of template parameters The inability to pass an arbitrary number of arguments to a function in a type safe manner The argument forwarding problem The proposed resolution is to introduce a syntax and semantics for variable length template argument lists usable with function templates via explicit template argument specification and with class templates along with a method of argument building using the same mechanism to pass an arbitrary number of function call arguments to a function in a typesafe manner 2 2 1 Motivation Variable length template parameter lists Variable length template parameter lists varargs allow a class or function template to accept some number possibly zero of template arguments beyond the number of template parameters specified This behavior can be simulated in C via a long list of defaulted template parameters e g a typelist wrapper may appear as struct unused template typename T1 unused typename T2 unused typename T3 unused typename T4 unused up to typename TN unused class list This technique is used by the Boost Tuples library 10 for the specification of class template std tuple in the library TR 11 and in the Boost metaprogramming library 9 Unfortunately this method leads to very long type names in error messages compilers tend to print the defaulted arguments and very long mangled names It is also not scalable to additional arguments without resorting to preprocessor magic 13 In all of these libraries and presumably many more an implementation based on template varargs would be shorter and would not suffer the limitations of the



Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view vararg_templates_n1483 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view vararg_templates_n1483 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?