Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-08 13:56:51


> > template <typename FUNCTOR,
> > typename RETURN_TYPE,
> > typename ARG1,
> > typename ARG2,
> > bool useCompare>

        UGGHH :-)

        You can get rid of functions of more than one
argument. They don't exist in mathematics, and they
shouldn't exist in C++ either.

        Use the below C program to generate the template

        struct_n<class T1, class T2, .. class Tn>

for all n up to a value given on the command line.

        Use these structures to pass multiple arguments.
It is MUCH better to put the complexity of multiple
arguments into exactly one place, namely the constructors
of the type 'struct_n', and make everything else accept
exactly one argument, than to try to handle functions
of multiple arguments in function.hpp.

        If you use 'struct_2', it makes sense to get
rid of 'pair', which is inconsistently named.
Unfortunately, you can't just typedef it away, because
the components are called 'first' and 'second' instead
of 'mem1' and 'mem2' (which is what they should have been
called).

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

static long seq=0;
void write_template_header(int ntypes) {
  printf("// dcl #%ld\n",seq++);
  int i;
  if(ntypes == 0) return;
  printf("template<\n");
  for (i = 1; i < ntypes; i++)
  printf(" class type%d,\n", i);
  printf(" class type%d\n>\n", i);

}

void write_template_header2(int ntypes) {
  printf("// dcl #%ld\n",seq++);
  int i;
  if(ntypes == 0) return;
  printf("template<class T,\n");
  for (i = 1; i < ntypes; i++)
  printf(" class type%d,\n", i);
  printf(" class type%d\n>\n", i);

}

void spc(int i) { while(i--) putchar(' '); }

void dcl_inst(char *kind, int ntypes, int indent, int offset=0) {
  int i;
  spc(indent);
  if(ntypes==0) printf("%s0\n",kind);
  else {
  printf("%s%d<\n",kind,ntypes);
  for (i = 1; i < ntypes; i++) {
      spc(indent+2); printf("type%d,\n",i+offset);
    }
    spc(indent+2); printf("type%d\n",i+offset);
    spc(indent); printf(">\n");
  }
}

void dcl_inst2(char *kind, int ntypes, int indent) {
  int i;
  spc(indent);
  printf("%s%d<T\n",kind,ntypes);
  for (i = 1; i <= ntypes; i++) {
    spc(indent+2); printf(",type%d\n",i);
  }
  spc(indent); printf(">\n");
}

/* Core builder */
void mk_struct(int ntypes) {
  int i;
  write_template_header(ntypes);
  printf("struct struct%d\n{\n", ntypes);
  printf(" typedef struct%d self;\n", ntypes);

  for (i = 1; i <= ntypes; i++)
  printf(" typedef type%d T%d;\n", i, i);
  for (i = 1; i <= ntypes; i++)
  printf(" T%d mem%d;\n", i, i);

  printf("\n");
  printf(" // rvalue->lvalue\n");
  printf(" self &ref() { return *this; }\n");

  printf("\n");
  printf(" // default ctor\n");
  printf(" struct%d(){}\n",ntypes);

  if(ntypes==2) { // specialisation
  printf("\n");
  printf(" // convert from STL pair\n");
  printf(" struct2(pair<type1,type2> a) :\n");
  printf(" mem1(a.first), mem2(a.second){}\n");
  }

  if(ntypes!=0) {
  printf("\n");
  printf(" // memberwise ctor\n");
  printf(" struct%d(\n",ntypes);
  for (i = 1; i < ntypes; i++)
  printf( " T%d const &init%d,\n", i, i);
  printf( " T%d const &init%d\n", i, i);
  printf( " ) :\n");

  for (i = 1; i < ntypes; i++)
  printf(" mem%d(init%d),\n", i, i);
  printf(" mem%d(init%d)\n", i, i);
  printf(" {}\n");
  }
  printf(" // generated copy ctor\n");
  printf(" // generated copy assignment\n");
  printf(" // generated destructor\n");
  printf("};\n");
}

void mk_val_projections(int ntypes) {
  int i;
  if(ntypes==0) return;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// projections\n");
  for(i=1; i<=ntypes; ++i) {
  write_template_header(ntypes);
  printf("type%d val%d(\n", i,i);
  dcl_inst("struct",ntypes,2);
  printf(" const &a\n");
  printf(") {\n");
  printf(" return a.mem%d\n;",i);
  printf("}\n\n");
  }
}

void mk_canonical_projections(int ntypes) {
  int i;
  if(ntypes==0) return;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// canonical projections\n");
  for(i=1; i<=ntypes; ++i) {
  write_template_header(ntypes);
  printf("struct1<type%d> proj%d(\n", i,i);
  dcl_inst("struct",ntypes,2);
  printf(" const &a\n");
  printf(") {\n");
  printf(" return struct1<type%i>(a.mem%d);\n",i,i);
  printf("}\n\n");
  }
}
void mk_split(int ntypes) {
  int i,j;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// split struct%d\n", ntypes);
  for(i=0; i<=ntypes; ++i) {
  printf("// split%d : %d->[%d,%d]\n", i, ntypes, i, ntypes-i);
  write_template_header(ntypes);
  printf("struct2<\n");
  dcl_inst("struct",i,2,0);
  printf(" ,\n");
  dcl_inst("struct",ntypes-i,2,i);
  printf(">\n");
  printf("split%d(\n",i);
  dcl_inst("struct", ntypes,2);
  printf(" const &x\n");
  printf(") {\n");
  printf(" return make_struct(\n");
  printf(" make_struct(\n");
  for(j=1; j<i; ++j)
  printf(" x.mem%d,\n",j);
    if(j==i)
  printf(" x.mem%d\n",j);
  printf(" )\n");
  printf(" ,\n");
  printf(" make_struct(\n");
  for(j=i+1; j<ntypes; ++j)
  printf(" x.mem%d,\n",j);
    if(j==ntypes)
  printf(" x.mem%d\n",j);
  printf(" )\n");
  printf(" );\n");
  printf("}\n\n");
  }
}

void mk_ref_projections(int ntypes) {
  int i;
  if(ntypes==0) return;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// reference projections\n");
  for(i=1; i<=ntypes; ++i) {
  write_template_header(ntypes);
  printf("type%d &ref%d(\n", i,i);
  dcl_inst("struct",ntypes,2);
  printf(" &a\n");
  printf(") {\n");
  printf(" return a.mem%d\n;",i);
  printf("}\n\n");
  }
}

void mk_ptr_projections(int ntypes) {
  int i;
  if(ntypes==0) return;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// pointer projections\n");
  for(i=1; i<=ntypes; ++i) {
  write_template_header(ntypes);
  printf("type%d *ptr%d(\n", i,i);
  dcl_inst("struct",ntypes,2);
  printf(" *a\n");
  printf(") {\n");
  printf(" return &(a->mem%d)\n;",i);
  printf("}\n\n");
  }
}

void mk_equality(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// Equality\n");
  write_template_header(ntypes);
  printf("bool operator ==(\n");
  dcl_inst("struct",ntypes,2);
  printf(" const &a,\n");
  dcl_inst("struct",ntypes,2);
  printf(" const &b\n");
  printf(") {\n return\n");
  for (i = 1; i < ntypes; i++)
  printf(" a.mem%d == b.mem%d &&\n", i,i);
  printf(" a.mem%d == b.mem%d;\n", i,i);
  printf("}\n");
}

void mk_inequality(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// Inequality\n");
  write_template_header(ntypes);
  printf("bool operator !=(\n");
  dcl_inst("struct",ntypes,2);
  printf(" const &a,\n");
  dcl_inst("struct",ntypes,2);
  printf(" const &b\n");
  printf(") {\n");
  printf(" return !(a==b);\n");
  printf("}\n");
}
void mk_output(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// output\n");
  write_template_header(ntypes);
  printf("ostream &operator <<(ostream &out,\n");
  dcl_inst("struct",ntypes,2);
  printf(" const &a\n");
  printf(") {\n");
  printf(" out <<\n");
  printf(" \"[\" <<\n");
  if(ntypes==0);
  else if(ntypes == 1) printf(" a.mem1 <<\n");
  else {
  printf(" a.mem1 << \", \" <<\n");
  for (i = 2; i < ntypes; i++)
    printf(" a.mem%d << \", \" <<\n",i);
  printf(" a.mem%d <<\n",i);
  }
  printf(" \"]\";\n");
  printf(" return out;\n");
  printf("}\n");
}

void mk_make_struct(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// struct Factory function\n");
  write_template_header(ntypes);
  dcl_inst("struct",ntypes,0);
  printf("make_struct(\n");
  for(i=1; i<ntypes; ++i)
  printf(" type%d const &val%d,\n",i,i);
  if(i==ntypes)printf(" type%d const &val%d\n",i,i);
  printf(") {\n");
  printf(" return\n");
  dcl_inst("struct",ntypes, 4);
  printf(" (\n");
  for(i=1; i<ntypes; ++i)
  printf(" val%d,\n",i);
  if(i==ntypes)printf(" val%d\n",i);
  printf(" );\n");
  printf("}\n");
}
void mk_diagonal(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// diagonal Factory function\n");
  printf("template<class T>\n");
  if(ntypes==0) printf("struct0 diag0(T){ return struct0(); }\n");
  else {
  printf("struct%d<",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" T,\n");
  printf(" T> diag%d(T const &a) { return make_struct(\n", ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" a,\n");
  if(i==ntypes)
  printf(" a\n");
  printf(" );\n");
  printf("}\n");
  }
}

void mk_associative_product(int ntypes, int j) {
  int i;
  write_template_header(ntypes);
  dcl_inst("struct",ntypes,0);
  printf("operator *(\n");
  dcl_inst("struct",j,2);
  printf(" const &a,\n");
  dcl_inst("struct",ntypes-j,2,j);
  printf(" const &b\n");
  printf(") {\n");
  printf(" return\n");
  dcl_inst("struct",ntypes, 4);
  printf(" (\n");

  for(i=1; i<=j; ++i)
  printf("%s a.mem%d",((i!=1)?",\n":""),i);
  for(; i<=ntypes; ++i)
  printf("%s b.mem%d",((i!=1)?",\n":""),i-j);

  printf("\n );\n");
  printf("}\n");
}

void mk_associative_product(int ntypes) {
  int j;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// associative products\n");
  for(j=0; j<=ntypes; ++j) mk_associative_product(ntypes,j);
}
void mk_associative_function_product(
  int args1,
  int rets1,
  int args2,
  int rets2
) {
  int i;
  int ntypes = args1+rets1+args2+rets2+2;
  write_template_header(ntypes);
  printf("struct func_%d_%d_%d_%d : \n", args1,args2,rets1,rets2);
  printf(" unary_function<\n");
  dcl_inst("struct",args1+args2,4);
  printf(" ,\n");
  dcl_inst("struct",rets1+rets2,4,args1+args2);
  printf(" >\n");

  printf("{\n");
  printf(" typedef type%d F1;\n", ntypes-1);
  printf(" typedef type%d F2;\n", ntypes);
  printf(" F1 f1;\n");
  printf(" F2 f2;\n");
  printf(" func_%d_%d_%d_%d(F1 f1_, F2 f2_) : f1(f1_), f2(f2_) {}\n",
    args1,args2, rets1,rets2);
  dcl_inst("struct", rets1+rets2,2,args1+args2);
  printf(" operator() (\n");
  dcl_inst("struct",args1+args2,4);
  printf(" const &x\n");
  printf(" ) const {\n");
  dcl_inst("struct",args1,4);
  printf(" a(\n");
  for(i=1; i<args1; ++i)
  printf(" x.mem%d,\n",i);
  if(i==args1);
  printf(" x.mem%d\n",i);
  printf(" );\n");
  dcl_inst("struct",args2,4,args1);
  printf(" b(\n");
  for(i=args1+1; i<args1+args2; ++i)
  printf(" x.mem%d,\n",i);
  if(i==args1+args2);
  printf(" x.mem%d\n",i);
  printf(" );\n");
  printf(" return flatten2(make_struct(f1(a), f2(b)));\n");
  printf(" }\n");
  printf("};\n");
}

void mk_flatten(int ntypes, int j) {
  printf("\n");
  write_template_header(ntypes);
  dcl_inst("struct",ntypes,0);
  printf("flatten2(\n");
  printf(" struct2<\n");
  dcl_inst("struct",j,4);
  printf(" ,\n");
  dcl_inst("struct",ntypes-j,4,j);
  printf(" > const &x\n");
  printf(") {\n");
  printf(" return val1(x) * val2(x);\n");
  printf("}\n");
}

void mk_ptm(int ntypes) {
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// ptm%d\n",ntypes);
  printf("//---------------------------------------\n");

  printf("\n");
  printf("template<class T> struct ptm%d {\n", ntypes);
  printf(" typedef typename T::T%d V;\n", ntypes);
  printf(" typedef V T::*ptm;\n", ntypes);
  printf(" ptm operator()()const {\n", ntypes,ntypes);
  printf(" return &T::mem%d;\n", ntypes);
  printf(" }\n");
  printf("};\n");
}

void mk_ref_struct(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// ref_struct%d \n",ntypes);
  printf("//---------------------------------------\n");

  write_template_header(ntypes);
  printf("struct ref_struct%d\n{\n", ntypes);
  printf(" // types\n");
  printf(" typedef ref_struct%d self;\n", ntypes);
  for (i = 1; i <= ntypes; i++)
  printf(" typedef type%d T%d;\n", i, i);

  printf("\n");
  printf(" // rvalue->lvalue\n");
  printf(" self &ref() { return *this; }\n");

  printf("\n");
  printf(" // members\n");
  for (i = 1; i <= ntypes; i++)
  printf(" T%d &mem%d;\n", i, i);

  printf("\n");
  printf(" // NO default ctor\n");
  printf(" // memberwise ctor\n");
  printf(" ref_struct%d(\n",ntypes);
  for (i = 1; i < ntypes; i++)
  printf( " T%d &init%d,\n", i, i);
  printf( " T%d &init%d\n", i, i);
  printf( " ) :\n");

  for (i = 1; i < ntypes; i++)
  printf(" mem%d(init%d),\n", i, i);
  printf(" mem%d(init%d)\n", i, i);
  printf(" {}\n");

  printf(" // construct from struct value\n");
  printf(" ref_struct%d(", ntypes);
  dcl_inst("struct",ntypes,6);
  printf(" &x) :\n");
  for (i = 1; i < ntypes; i++)
  printf(" mem%d(x.mem%d),\n", i, i);
  printf(" mem%d(x.mem%d)\n", i, i);
  printf(" {}\n");

  printf("\n");
  printf(" // get() constructs value struct\n");
  dcl_inst("struct",ntypes,2);
  printf(" get()const {\n");
  printf(" return\n",ntypes);
  dcl_inst("struct",ntypes,6);
  printf(" (\n");
  for (i = 1; i < ntypes; i++)
  printf(" mem%d,\n", i);
  printf(" mem%d\n", i);
  printf(" );\n");
  printf(" }\n");

  printf("\n");
  printf(" // assignment from value struct\n");
  dcl_inst("ref_struct",ntypes,2);
  printf(" &operator=(\n");
  dcl_inst("struct", ntypes,4);
  printf(" const &x) {\n");
  for (i = 1; i <= ntypes; i++)
  printf(" mem%d=x.mem%d;\n", i, i);
  printf(" return *this;\n",ntypes);
  printf(" }\n");

  printf("\n");
  printf(" // copy assignment\n");
  dcl_inst("ref_struct",ntypes,2);
  printf(" &operator=(self const &x) {\n");
  for (i = 1; i <= ntypes; i++)
  printf(" mem%d=x.mem%d;\n", i, i);
  printf(" return *this;\n",ntypes);
  printf(" }\n");

  printf(" // generated copy ctor rebinds references\n");
  printf(" // generated destructor is trivial\n");

  printf("};\n");
}

void mk_ref(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// ref_struct Factory function\n");
  write_template_header(ntypes);
  dcl_inst("ref_struct",ntypes,0);
  printf("make_ref(\n");
  for(i=1; i<ntypes; ++i)
  printf(" type%d &val%d,\n",i,i);
  printf(" type%d &val%d\n",i,i);
  printf(") {\n");
  printf(" return\n");
  dcl_inst("ref_struct",ntypes, 4);
  printf(" (\n");
  for(i=1; i<ntypes; ++i)
  printf(" val%d,\n",i);
  printf(" val%d\n",i);
  printf(" );\n");
  printf("}\n");
}

void mk_ptm_struct(int ntypes) {
  int i;
  printf("//---------------------------------------\n");
  printf("// ptm_struct%d \n",ntypes);
  printf("//---------------------------------------\n");

  write_template_header2(ntypes);
  printf("struct ptm_struct%d\n{\n", ntypes);
  for (i = 1; i <= ntypes; i++)
  printf(" typedef type%d T::* T%d;\n", i, i);
  for (i = 1; i <= ntypes; i++)
  printf(" T%d mem%d;\n", i, i);

  printf("\n");
  printf(" ptm_struct%d(\n",ntypes);
  for (i = 1; i < ntypes; i++)
  printf( " T%d init%d,\n", i, i);
  printf( " T%d init%d\n", i, i);
  printf( " ) :\n");

  for (i = 1; i < ntypes; i++)
  printf(" mem%d(init%d),\n", i, i);
  printf(" mem%d(init%d)\n", i, i);
  printf(" {}\n");

  printf("\n");
  printf(" ptm_struct%d() :\n",ntypes);
  for (i = 1; i < ntypes; i++)
  printf(" mem%d(0),\n", i);
  printf(" mem%d(0)\n", i);
  printf(" {}\n");

  dcl_inst("ref_struct",ntypes,2);
  printf(" bind_pointer(T *p)const {\n");
  printf(" return\n");
  dcl_inst("ref_struct", ntypes,6);
  printf(" (\n");
  for (i = 1; i < ntypes; i++)
  printf(" p->*mem%d,\n", i);
  printf(" p->*mem%d\n", i);
  printf(" );\n");
  printf(" }\n");
  printf("};\n");
}

void mk_operator_arrow_ast(int ntypes) {
  write_template_header2(ntypes);
  dcl_inst("ref_struct",ntypes,2);
  printf("operator->*(T *p,\n");
  dcl_inst2("ptm_struct",ntypes,2);
  printf(" const &x) {\n");
  printf(" return x.bind_pointer(p);\n");
  printf("}\n");
}

void mk_canonical_ptm_struct(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// make_canonical_ptm_struct Factory functoid\n");
  write_template_header(ntypes);
  printf("struct make_canonical_ptm_struct%d {\n", ntypes);
  printf(" typedef");
  dcl_inst("struct", ntypes, 4);
  printf(" T;\n");
  dcl_inst2("ptm_struct",ntypes,2);
  printf(" operator()()const {\n");
  printf(" return\n");
  dcl_inst2("ptm_struct",ntypes,6);
  printf(" (\n");
  for (i = 1; i < ntypes; i++)
  printf(" &T::mem%d,\n", i);
  printf(" &T::mem%d\n", i);
  printf(" );\n");
  printf(" }\n");
  printf("};\n");
}

void mk_nonassociative_function_product(int ntypes) {
  int i;
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// NON-ASSOCIATIVE PRODUCT OF FUNCTIONS(any kind)\n");

  write_template_header(ntypes);
  printf("struct parallel%d :\n" , ntypes);

  printf(" unary_function<\n");
  printf(" struct%d<\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" typename type%d::argument_type,\n", i);
  printf(" typename type%d::argument_type\n",i);
  printf(" >,\n");
  printf(" struct%d<\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" typename type%d::result_type,\n", i);
  printf(" typename type%d::result_type\n",i);
  printf(" >\n");
  printf(" >,\n");

  printf(" struct%d<\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" type%d,\n", i);
  printf(" type%d\n", i);
  printf(" >\n");

  printf("{\n");
  for(i=1; i<=ntypes; ++i)
  printf(" type%d mem%d;\n",i,i);
  printf(" parallel%d(\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" type%d mem%d_,\n",i,i);
  printf(" type%d mem%d_\n",i,i);
  printf(" ) : struct%d<\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" type%d,\n", i);
  printf(" type%d\n", i);
  printf(" >(\n");
  for(i=1; i<ntypes; ++i)
  printf(" mem%d_,\n",i);
  printf(" mem%d_\n",i);
  printf(" )\n");

  printf("{}\n");
  printf("\n");
 printf(" struct%d<\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" typename type%d::result_type,\n",i);
  printf(" typename type%d::result_type\n",i);
  printf(" >\n");
  printf("operator() (\n");
  printf(" struct%d<\n",ntypes);
  for(i=1; i<ntypes; ++i)
  printf(" typename type%d::argument_type,\n",i);
  printf(" typename type%d::argument_type\n",i);
  printf(" > const &x\n");
  printf(") const {\n");
  printf(" return make_struct(\n");
  for(i=1; i<ntypes; ++i)
  printf(" mem%d(val%d(x)),\n",i,i);
  printf(" mem%d(val%d(x))\n",i,i);
  printf(" );\n");
  printf(" }\n");
  printf("};\n");
}

void write_struct(int ntypes)
{
  printf("//=======================================\n");
  printf("// ORDER t%d\n",ntypes);
  printf("//=======================================\n");
  printf("\n");
  printf("//---------------------------------------\n");
  printf("// struct%d \n",ntypes);
  printf("//---------------------------------------\n");

  if(ntypes==0) { // ---------------------------------------

  printf("struct struct0\n");
  printf("{\n");
  printf(" typedef struct0 self;\n");
  printf("\n");
  printf(" // rvalue->lvalue\n");
  printf(" self &ref() { return *this; }\n");
  printf("\n");
  printf(" // default ctor\n");
  printf(" struct0(){}\n");
  printf(" // generated copy ctor\n");
  printf(" // generated copy assignment\n");
  printf(" // generated destructor\n");
  printf(" friend bool operator ==(struct0 const &, struct0 const &) {
return true; }\n");
  printf(" friend bool operator !=(struct0 const &, struct0 const &) {
return false; }\n");
  printf(" friend struct0 make_struct() { return struct0 (); }\n");
  printf(" friend ostream &operator <<(ostream &out,struct0 const &a)
{\n");
  printf(" out << \"[\" <<\"]\";\n");
  printf(" return out;\n");
  printf(" }\n");
  printf("};\n");

  mk_diagonal(0);
  return;
  } // ----------------------------------

  int i;

  mk_struct(ntypes);
  mk_canonical_projections(ntypes);
  mk_val_projections(ntypes);
  mk_ref_projections(ntypes);
  mk_ptr_projections(ntypes);
  mk_equality(ntypes);
  mk_inequality(ntypes);
  mk_output(ntypes);
  mk_make_struct(ntypes);
  mk_diagonal(ntypes);
  mk_associative_product(ntypes);

  // hack because flatten uses struct2 -- which isn't declared
  // yet if ntypes == 1
  if(ntypes ==2) {
    mk_flatten(1,0),mk_flatten(1,1);
    mk_split(0), mk_split(1);
  }
  if(ntypes>=2) {
    for(int j=0; j<=ntypes; ++j) mk_flatten(ntypes,j);
    mk_split(ntypes);
  }

  mk_ptm(ntypes);
  mk_ref_struct(ntypes);
  mk_ref(ntypes);

  mk_ptm_struct(ntypes);
  mk_operator_arrow_ast(ntypes);
  mk_canonical_ptm_struct(ntypes);

  mk_nonassociative_function_product(ntypes);
};

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

  if (argc != 2) {
    fprintf(stderr, "usage: %s num\n", argv[0]);
    exit(1);
  }

  printf("// Generated by mkstruct template generator\n"
  "// template implementation by John Max Skaller\n"
  "\n#ifndef STRUCT_H\n"
  "#define STRUCT_H\n\n"
  "#include <iostream.hpp>\n"
  "#include <pair.hpp>\n"
  "#include <function.hpp>\n"
  "\n"
  "#if !defined(UESTL_NAMESPACES_BROKEN)\n"
  "namespace MaxTal { namespace structures {\n"
  " using functions::bases::unary_function;\n"
  " using functions::bases::binary_function;\n"
  " using functions::bases::unary_procedure;\n"
  " using functions::bases::binary_procedure;\n"
  "#endif\n"
  );

  n = atoi(argv[1]);
  if (n < 0)
    fprintf(stderr, "%s: invalid # of members: %s (must be >= 0)\n",
      argv[0], argv[i]);
  else {
    int args1, args2, rets1, rets2;
  for(i=0; i<=n; ++i) write_struct(i);
  for(args1=0; args1<=n; ++args1)
    for(args2=0; args2<=n; ++args2)
      if(args1+args2<=n)
        for(rets1=0; rets1<=n; ++rets1)
          for(rets2=0; rets2<=n; ++rets2)
            if(rets1+rets2<=n)
              mk_associative_function_product(args1, rets1, args2,
rets2);
  }
  printf("#if !defined(UESTL_NAMESPACES_BROKEN)\n");
  printf("\n} } // end MaxTal\n");
  printf("#endif\n");
  printf("\n#endif // STRUCT_H\n\n");
  return 0;
}

-- 
John (Max) Skaller, mailto:skaller_at_[hidden]
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk