Hi Daniel,

I'm not 100% sure about this answer, but here goes...

When defining a concept, identifiers that do not explicity quantify type attributes (such as 'const' or '&') are defaulted to 'const type&'.  So, in your 'Function<F>' concept, the use of 'source_type' and 'target_type' on line 19 will become:
const target_type& operator()(const source_type& x);
As far as I know, there is no way to enforce "copy by value" arguments when defining a concept - but there also seems to be no reason to do so since a 'const type&' will generally suffice - and provide better flexibility for defining concept_maps.

Regardless, the use of 'const type&' should be ok for your test case.

I don't really understand the error message for line 53.  However, I wonder if this is just a poor message for another error.  In your 'test' function, the 'f' parameter is specified as "copy by value", but the 'Function' concept does not specify that the type is copy constructible, so this use is not valid (I think).  There are a couple of ways of fixing this:
  1. Add another requires clause to 'test' that 'F' be CopyConstructible
  2. Change 'test' to accept it's F parameter as a reference.
Tom.

Daniel Lincke wrote:
Hi ConceptGCC-users,

I tried ConceptGCC and my first programm don't work. Here is the code:

+++++++++++++++++++++++++++++++++++++++++++++++++
#ifdef __GXX_CONCEPTS__
#include <concepts>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace std;

#ifdef __GXX_CONCEPTS__
concept Function<class F> {
typename source_type;
typename target_type;

target_type operator() (source_type x); // LINE 19
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
};
#endif

class Test_Function1 {
public:
typedef int source_type;
typedef int target_type;

int operator() (int t) {
return (t*2);
}
};


#ifdef __GXX_CONCEPTS__
concept_map Function<Test_Function1> {
typedef Test_Function1::source_type source_type;
typedef Test_Function1::target_type target_type;

target_type operator() (source_type x) {
//return Test_Function1::operator() (x);
Test_Function1 f;
return f(x);
}
}
#endif

template<class F>
#ifdef __GXX_CONCEPTS__
requires Function<F>
#endif
void test (F f) {
for (int i=0; i<10; ++i)
{cerr << i << " -> " << f(i) << endl;} // LINE 53
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

int main (int argc, char *argv[]) {

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++

ConceptGCC reports the following error:

/opt/conceptgcc-4.3/bin/conceptg++ -c -o main.o main.cpp
main.cpp: In function ‘void test(F)’:
main.cpp:53: error: invalid initialization of reference of type ‘const
Function<F>::source_type&’ from expression of type ‘F’
main.cpp:19: error: in passing argument 1 of ‘Function<F>::target_type
Function<F>::operator()(const Function<F>::source_type&)’
make: *** [main.o] Fehler 1


lines 19 and 53 are marked in the listing above. I don't understand the
error: in passing argument 1 of ‘Function<F>::target_type
Function<F>::operator()(const Function<F>::source_type&)’
message, as there is no such operator in the concept Function, at least
not with an const reference as input parameter.

Greets and Thanks for reducing my confusion ;)
Daniel
_______________________________________________
ConceptGCC mailing list
ConceptGCC@generic-programming.org
http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc
  

--
Oracle Email Signature Logo
Tom Honermann | Senior Principal Software Engineer | 503.276.2354
Oracle PeopleTools Development
1211 SW 5th Ave, Suite 9080, Portland, OR 97204