Topic: Matching of template template parameters


Author: rl@home.cs.tu-berlin.de (Roman Leshchinskiy)
Date: Tue, 31 Dec 2002 16:49:54 +0000 (UTC)
Raw View
Hi,

the following problem(s) came up in the context of a rather weird
library for template metaprogramming. First, consider the following
declarations:

template<typename T, typename Args> struct apply;
template<template<typename> class F,
          typename X0, typename Args>
struct apply< F<X0>, Args >;    // (1)
template<template<typename, typename> class F,
                   typename X0, typename X1, typename Args>
struct apply< F<X0,X1>, Args >; // (2)

I assume the above is legal code. Now, given the following declaration

struct none;
template<typename X = none, typename Y = none> struct plus;

what specialization does e.g. apply<plus<int>, double> match? GCC says
its ambiguous because both (1) and (2) match, however issue 150 of the
Standard Core Language Closed Issues seems to suggest that (1) shouldn't
match because default arguments shouldn't be considered in this case. Is
this interpretation correct?

Next, we add the following specialization

template<template<typename, typename> class F,
          typename X0, typename Args>
struct apply< F<X0, none>, Args >; // (3)

Is (3) more specialized than (2) (and (1), should it match), i.e. will
apply<plus<int>, double> match (3) now? Common sense suggests so, but my
compiler complains even if I remove (1) and I haven't really been able
to understand what the standard tries to say here.

Bye

Roman

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: cpdaniel@nospam.mvps.org ("Carl Daniel")
Date: Tue, 31 Dec 2002 17:09:58 +0000 (UTC)
Raw View
"Roman Leshchinskiy" <rl@home.cs.tu-berlin.de> wrote in message
news:3E117A2B.900@home.cs.tu-berlin.de...
> what specialization does e.g. apply<plus<int>, double> match? GCC says
> its ambiguous because both (1) and (2) match, however issue 150 of the
> Standard Core Language Closed Issues seems to suggest that (1) shouldn't
> match because default arguments shouldn't be considered in this case. Is
> this interpretation correct?

Agreed.  Both MSVC 7.1 and Comeau 4.3 agree as well that (2) is the chosen
specialization.

>
> Next, we add the following specialization
>
> template<template<typename, typename> class F,
>           typename X0, typename Args>
> struct apply< F<X0, none>, Args >; // (3)
>
> Is (3) more specialized than (2) (and (1), should it match), i.e. will
> apply<plus<int>, double> match (3) now? Common sense suggests so, but my
> compiler complains even if I remove (1) and I haven't really been able
> to understand what the standard tries to say here.

3 is more specialized than (1) or (2).  Again, both VC7.1 and Comeau 4.3
agree that (3) is the chosen specialization.

What version of GCC are you using?

-cd

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]