I've started typeclassing STL containers.

At present, I'm using interscript to generated the code,
for example:

@def tcmkseq(n):
  c = n+'[v]'
  it = n+'_iterator[v]'

  tangle('  instance[v] Sequence['+c+','+it+',v] {')
  tangle('    fun len: '+c+' -> int = "$1.size()";')
  tangle('    fun empty: '+c+' -> bool = "$1.empty()";')
  tangle('    fun begin : '+c+'-> '+it+'= "$1.begin()";')
  tangle('    fun end : '+c+'-> '+it+'= "$1.end()";')
  tangle('    proc erase : lvalue['+c+'] * '+it+' = "$1.erase($1);";')
  tangle('    proc erase_between : lvalue['+c+'] * '+it+' * '+it+' =
"$1.erase($1,$2);";')
  tangle('    proc clear : lvalue['+c+'] = "$1.clear();";')
  tangle('  }')

@tcmkseq('Stl::Vector::stl_vector')

However I have tested this and it seems to work:

macro proc Seq(c,it) {
  instance[v] Sequence[c,it,v] {
    fun len: c -> int = "$1.size()";
    fun empty: c -> bool = "$1.empty()";
    fun begin : c -> it = "$1.begin()";
    fun end : c -> it= "$1.end()";
    proc erase : lvalue[c] * it = "$1.erase($1);";
    proc erase_between : lvalue[c] * it * it = "$1.erase($1,$2);";
    proc clear : lvalue[c] = "$1.clear();";
  }
}

Seq(Stl::Vector::stl_vector[v],Stl::Vector::stl_vector_iterator[v]);

What doesn't work is a typedef in the instance:

instance[v] Seq(
  Stl::Vector::stl_vector[v],
  Stl::Vector::stl_vector_itertor[v]
)
{
  typedef c = Stl::Vector::stl_vector[v];
  fun len: c -> int = ...

This bombs out with a vs/ts mismatch.. no idea why at the moment.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to