Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: Associated type as return type.

From: Doug Gregor (dgregor_at_[hidden])
Date: 2008-08-19 15:52:40


On Aug 19, 2008, at 1:56 PM, hirohito none wrote:

>> How should the compiler deduce Foo<Bar>::return_type?
>
> So the compiler does not deduce associated types?
> It just looking if there is function that satisfy given associated
> function, and set its associated type which is return type of
> associated function to the same type as function ?
> so compiler thinks as this?
>
> auto concept Foo< typename T >
> {
> requires std::CopyConstructible< T > ;
> typename result_type ;// type i don't know it right now.
> // hmm, that type used as return type of function.
> result_type function(T x)

ConceptGCC does deduce return types, however...

>
> // I shall not deduce result_type.
> // so this default implementation will never be used even if there
> is no required function.
> { return x.value ; }
> }

ConceptGCC should be giving an error here, because "x.value" is not a
valid default implementation. Default implementations can only use
operations known to work on the type, e.g., other operations within
the concept Foo.

>> I think it should work if you give the result_type a default
> I tryed it. It does not work in Alpha 7. I don't know ConceptGCC is
> correct or not.
>
>
> and I still don't know how to write function templates with concepts
> that access template parametor's member variables.

This cannot be done directly. You'll need to write an accessor
function like "function" above, and then provide an implementation for
"function" within a concept map.

   - Doug