
12 Jan
2005
12 Jan
'05
1:57 p.m.
David Abrahams wrote:
Ben Hutchings wrote:
Well the first attempt doesn't solve the problem because it requires an extra parameter. The second attempt solves it but I don't think you're supposed to make use of other templates.
Any solutions is allowable, though that one is not particularly elegant.
I think the expected solution would be more like this:
template<typename T> struct add_const_ref { typename T const & type; };
template<typename T> struct add_const_ref<T &> { typename T & type; };
Actually there's a much more concise solution using the type traits library. That is, after all, the focus of the chapter.
Remind me not to talk about books I haven't read in future... Ben.