xtd


 

what's that?

xtd is a tiny replacement (a single file of about 1.6k lines) for the functional (and cmath) header(s) of the standard C++ library. If you've got any problem with it please submit a bug report.
 

related works

Some functional libraries are available for people who want to express functional pieces of code in C++: FC++ by Brian McNamara and Yannis Smaragdakis, FACT! by Jörg Striegnitz, and the Boost Lambda Library by Jaakko Järvi and Gary Powell. They provide much more functional features than we do, so we clearly do not pretend to replace those libraries. Instead we propose the smallest subset (just one file!) that allows to write functions in a very convenient way when using some std algorithms. The way we have designed classes in xtd relies on the static C++ object-oriented paradigm (SCOOP) as described here.
 

authors

Thierry Géraud (corresponding author ), Matthieu Baechler, Christopher Faulet, and Sébastien Lagarde.
 

sample use

std C++xtd
remove_if(L.begin(), L.end(),
          compose2(logical_and<bool>(),
                   bind2nd(greater<int>(), 100),
                   bind2nd(less<int>(), 1000)));
remove_if(L.begin(), L.end(),
          x > 100 && x < 1000);

 

readme

Get the files and follow the proposed tour. This code compiles with:
 

last snapshot


 

features

2004-feb-10: 2004-feb-06: 2004-feb-04: 2004-jan-30: 2004-jan-25: 2004-jan-24:
  • definition of traits for expression return type
  • support for function expressions through xtd::fun(..)
  • expressions accept expressions as argument: for instance (2*x)(x+1) means (2*(x+1)) and (x*y+1)(3*x, x+2) means ((3*x)*(x+2)+1)
  • expressions accept some constant values (the ones whose type is int, float, or double) without precising cst(..)
  • type promotion: (x + 3.14f) with x being a placeholder for int data will give float
  • ability to define meta-function objects (such as struct sqr { template<class T> T operator()(T t) const {return t*t;} };) and to involve them in expressions: fun(sqr)(x + 1) is ok
first draft (2002):
  • expressions mimics and rely on the unary or binary std ones
  • expressions derive from expr (so that expression templates are disambiguated)
  • constants in expressions need to be wrapped with cst
  • sample code is: cst(2) * x + cst(1)
  • known problem: type promotion is not handled

 

to-do list

  • handle methods (such as std::mem_ptr does)
  • handle complex and array types in expressions
  • test with other compilers/platforms than g++ and icc
  • address performance issues (in particular, ensure that nrvo is effective)
  • write a user guide
  • write a conception white paper
  • add "motivation / related works / thanks" section to this page
  • then start an alpha-test process...