Indiana Unversity logo[ConceptGCC]

ConceptGCC :

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

From: Jacob Smith (jaroslov_at_[hidden])
Date: 2007-09-19 11:48:00


The code below compiles on (GCC) 4.3.0 20070330 (experimental)
(Indiana University ConceptGCC Alpha 7 Prerelease).

Some notes about the code you wrote:
1) use the cstdlib and cstdio headers and not the (deprecated) headers
stdlib.h and stdio.h
2) the iostream operators have not been ported for use with concepts,
so use the "print-hack" function defined below; this erases the
constraints; this is a hack.
3) "operator xxx ()" functions require that the first argument be the
const/non-const variant of the type that the operator is applied to.
Thus "operator * ()" as a member for a class F becomes "operator * (F
const&)" or "operator * (F&)" depending upon the const-ness required.
4) you must explain to the function "test" that the source-type of the
concept is the same-type as the integer you are passing ...
"source-type" and "int" are not the same thing without a same-type. 5)
In your concept you define a non-member function "apply"; in "test"
you use a member function "apply(int)". Be sure that your constraints
meet your requirements.

-Jacob S.

************************

#include <concepts>
#include <cstdlib>
#include <cstdio>
#include <iostream>

concept Fun<typename T>
{
  std::Regular source_type;
  std::Regular target_type;

  target_type operator () (T const&, source_type const&);
}

struct F1
{
  typedef std::size_t source_type;
  typedef std::size_t target_type;

  target_type operator () (source_type const& s) const
  {
    return 0;
  }
};

concept_map Fun<F1>
{
  typedef F1::source_type source_type;
  typedef F1::target_type target_type;
}

template <typename T>
void print_hack (T const& t)
{
  std::cout << t << std::endl;
}

template <typename F>
requires Fun<F>, std::SameType<F::source_type,std::size_t>
void test (F const& f)
{
  for (std::size_t i=0; i<10; ++i)
    print_hack (f(i));
}

int main (int argc, char *argv[]) {
  F1 f1;
  test (f1);
}

On 9/19/07, Karl Meerbergen <Karl.Meerbergen_at_[hidden]> wrote:
> Shouldn't you have
> void T::call() in your concept?
> This works with my installation.
>
> Karl
>
>
>
> Daniel Lincke wrote:
>
> >Hi,
> >
> >things are even worse :( ...
> >
> >look at this code:
> >
> >#include <concepts>
> >
> >#include <stdlib.h>
> >#include <stdio.h> // file I/O streams
> >#include <iostream>
> >
> >using namespace std;
> >
> >concept TEST<class T> {
> >void call();
> >};
> >
> >template<class T>
> >requires TEST<T>, DefaultConstructible<T>
> >void test () {
> >T t;
> >t.call();
> >}
> >
> >int main (int argc, char *argv[]) {
> >}
> >
> >
> >leading to the error:
> >/opt/conceptgcc-4.3/bin/conceptg++ -c -o main.o main.cpp
> >main.cpp: In function 'void test()':
> >main.cpp:19: error: 'struct T' has no member named 'call'
> >make: *** [main.o] Fehler 1
> >
> >:confused:
> >No idea what's going wrong here ...
> >(Might this be a problem with the installation of conceptgcc?)
> >
> >Best, dl
> >_______________________________________________
> >ConceptGCC mailing list
> >ConceptGCC_at_[hidden]
> >http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc
> >
> >
>
>
> _______________________________________________
> ConceptGCC mailing list
> ConceptGCC_at_[hidden]
> http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc
>
>
>