Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: Requiring a function template specialization

From: Douglas Gregor (doug.gregor_at_[hidden])
Date: 2007-06-07 08:17:33


On Jun 6, 2007, at 8:40 PM, Walter E Brown wrote:

> On 2007-06-06 7:22 PM, Douglas Gregor wrote:
>> concept Foo<class T> {
>> T foo();
>> }
>>
>> You can call it as just "foo()", or (to be more specific),
>> Foo<T>::foo
>> ().
>
> Thank you. I understand your point regarding a primary template
> and had
> also tried:
>
> #include <concepts>
>
> template< class T >
> T
> foo();
>
> concept Foo< class T >
> {
> template<>
> T
> foo<T>();
> };

A primary template and its specializations need to live in the same
scope... the primary template for "foo" lives in the global scope
whereas the specialization lives in concept "Foo".

> The intent is to be able to call foo<mytype>(), and to require the
> existence of such a specialization in order for mytype to meet the Foo
> concept. How can I better express this?

One may be able to do something tricky with templates and same-type
constraints, but ConceptGCC doesn't handle it now.

   concept Foo<class T> {
     template<typename U>
       requires SameType<T, U>
       T foo();
   }

I don't think that says precisely what you want, though. It would not
require the user to provide a specialization for foo<T>; rather, it
says that there needs to be a foo template that can be instantiated
with 'T'.

        - Doug