Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Need some help -- can't find the error in this code.

From: Daniel Lincke (daniel.lincke_at_[hidden])
Date: 2007-09-17 08:27:29


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