Topic: Allowing decltype to be used with type arguments (rather than just expressions)


Author: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
Date: Wed, 7 Jul 2010 11:19:52 CST
Raw View
It appears that the current wording only allows decltype to be called with
an expression.  However, it would be convenient (and seemingly quite trivial
to implement) if it could serve as an identity mapping if used with a type,
e.g. as the existing typeof facility in GCC (and probably other compilers)
supports.

The use case I have in mind is to be able to define a macro that can
automatically wrap either a type or value argument into a form suitable for
passing as a template type argument.  Using GCC's typeof, this can be
implemented as:

template <typename T, typename> T wrapper();
template <typename T, T X> boost::mpl::integral_c<T, X> wrapper();

#define WRAP(x) decltype(wrapper<typeof(x),x>())

I don't see any way to achieve this without the identity mapping on type
argument functionality of GCC's typeof.  wrapper could be overloaded for
several types, but it doesn't seem possible to handle arbitrary non-type
template arguments.

I imagine that this sort of wrapping would be useful for a number of
purposes, and one particular purpose of interest to me is an improved syntax
for Boost.Parameter-style keyword arguments for templates.

Any thoughts?

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]