Topic: [Q] Dependent template arguments


Author: Stephen Cleary <csclear@my-deja.com>
Date: 2000/07/12
Raw View
On Fri, 30 Jun 2000 06:08:17 CST, "Gabor Greif" <gabor@no.netopia.com>
wrote:

>On Thu, Jun 29, 2000 7:16 Uhr, Stephen Cleary <mailto:csclear@my-
deja.com>
>wrote:
>>In article <B575744D-A430A@192.109.102.124>,
>>  "Gabor Greif" <gabor@no.netopia.com> wrote:
>>> I am evaluating what degree of dependency of template arguments is
>>> permitted by the standard...
>>>
>>> template <typename T, template <T> class F>
>>> struct foo {};
>>>
>>> Admittedly my example is rather contrived, but I did not find any
>>hint in
>>> the standard that this kind of dependency would be disallowed.
>>
>>Since F is a template template argument, it needs a template parameter
>>list.  "<T>" is not a template parameter list.
>
>You seem to confuse things here.

You are correct.  I was confused!

I see nothing in the Standard to disallow the above.  Borland's C++
Builder 4 compiles it without complaint.

 -Steve


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Stephen Cleary <csclear@my-deja.com>
Date: 2000/06/28
Raw View
In article <B575744D-A430A@192.109.102.124>,
  "Gabor Greif" <gabor@no.netopia.com> wrote:
> I am evaluating what degree of dependency of template arguments is
> permitted by the standard...
>
> template <typename T, template <T> class F>
> struct foo {};
>
> Admittedly my example is rather contrived, but I did not find any
hint in
> the standard that this kind of dependency would be disallowed.

Since F is a template template argument, it needs a template parameter
list.  "<T>" is not a template parameter list.

You could do:
  template <typename T, template <T C> class F>
  struct foo {};
where F takes a non-type template argument of type T, or:
  template <typename T, template <typename> class _F>
  struct foo { typedef _F<T> F; };
where F takes a type template argument, which is T, or (if you *really*
want it in the template parameter list):
  template <typename T, template <typename> class _F,
      typename F = _F<T> >
  struct foo {};

        -Stephen Cleary


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Gabor Greif" <gabor@no.netopia.com>
Date: 2000/06/30
Raw View
On Thu, Jun 29, 2000 7:16 Uhr, Stephen Cleary <mailto:csclear@my-deja.com>
wrote:
>In article <B575744D-A430A@192.109.102.124>,
>  "Gabor Greif" <gabor@no.netopia.com> wrote:
>> I am evaluating what degree of dependency of template arguments is
>> permitted by the standard...
>>
>> template <typename T, template <T> class F>
>> struct foo {};
>>
>> Admittedly my example is rather contrived, but I did not find any
>hint in
>> the standard that this kind of dependency would be disallowed.
>
>Since F is a template template argument, it needs a template parameter
>list.  "<T>" is not a template parameter list.

You seem to confuse things here.

In my example F would be a template template argument of foo
and T the _kind_ of an unnamed (non-type) template argument of F.


I also could have written

template <typename T, template <T ARG> class F>
struct foo {};
(you mention this form in your reply)

but writing ARG is redundant just as parameter names in function pointer
types.

Assume I want to instantiate foo with int as the first parameter:

foo<int, TEMPLATE>();

then TEMPLATE must be a class template defined thus:

template <int I>
struct TEMPLATE {};

Hope this makes things clear.

But my original question still goes unanswered. Is the demonstrated
dependency of template arguments legal by the standard? If no, why and if
yes, are there compilers that support it?

 Gabor


---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Gabor Greif" <gabor@no.netopia.com>
Date: 2000/06/22
Raw View
I am evaluating what degree of dependency of template arguments is
permitted by the standard...

The below snippet compiles successfully with como:

template <int I, void (*)(int (&i)[I])>
struct foo {};

void bar(int (&i)[3]) {}

int main ()
{
 foo<3,bar>();
}


Taking the example one level farther:

template <typename T, template <T> class F>
struct foo {};

template <int>
struct bar {};

int main ()
{
 foo<int,bar>();
}

I get this error:

"17987.c", line 1: error: a parameter of a template template parameter
cannot
          depend on the type of another template parameter
  template <typename T, template <T> class F>

Admittedly my example is rather contrived, but I did not find any hint in
the standard that this kind of dependency would be disallowed.

I could imagine situations where the above could be put to good use.

That's the lawyers' opinion on this?

Thanks,

 Gabor


---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]