Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: Associated type as return type.

From: Jacob Smith (jaroslov_at_[hidden])
Date: 2008-08-18 14:47:00


Since the struct 'Bar' does not have a function that satisfies the
requirements of your concept, you have to add a concept_map, for example:

concept_map Foo<Bar> {
  typedef int result_type;
  result_type& value (Bar& b) { return b.value; }
}

Allows the code to compile just fine with conceptg++ (GCC) 4.3.0 20070330
(experimental) (Indiana University ConceptGCC Alpha 7 Prerelease) (r681).
This is clearly specified in the error messages the code gives:

hirohito.cpp:19:21: error: no newline at end of file
hirohito.cpp: In function 'int main()':
hirohito.cpp:19: error: no matching function for call to 'f(Bar)'
hirohito.cpp:12: note: candidates are: void f(T) [with T = Bar]
<requirements>
hirohito.cpp:19: note: no concept map for requirement 'Foo<Bar>'

The line "no concept_map for requirement 'Foo<Bar>'" says that a concept_map
is needed.

-j.

On Mon, Aug 18, 2008 at 1:06 PM, hirohito none <hitobasira_at_[hidden]> wrote:

> Following code can't be compiled with ConceptGCC 4.3.0 Alpha 7
>
> #include <concepts>
> auto concept Foo < typename T >
> {
> requires std::CopyConstructible< T > ;
> typename result_type ;
> requires std::CopyAssignable< result_type, int > ;
> result_type & value( T & x ) { return x.value ; }
> }
>
> template < typename T > requires Foo< T >
> void f( T x )
> { value(x) = 0 ; }
>
> struct Bar
> { int value ; } ;
>
> int main()
> { f(Bar()) ; }
>
> If concept does not allow above code, how can i write following C++03
> code with concept?
>
> template < typename T >
> void f( T x )
> { x.value = 0 ; }
> _______________________________________________
> ConceptGCC mailing list
> ConceptGCC_at_[hidden]
> http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc
>