Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-10 02:24:24


On Thu, Oct 09, 2003 at 03:34:03PM -0400, Hugo Duncan wrote:
> struct myfn {
> template < typename U >
> void operator()(const boost::mpl::identity<U>&) {
> std::cout << typeid(U).name() << std::endl;
> }
> };
...
> BTW, what do you call a class with a templated operator(), like myfn above?

I don't know. Is there a "standard" name, either in the C++ community,
or in the Boost community?

It might be useful to have a "standard" name for

 - classes which define non-template operator(),
      and instances of those classes

 - classes which define non-template operator() and work with result_of,
      and instances of those classes

 - classes which define template operator(),
      and instances of those classes

 - classes which define template operator() and work with result_of,
      and instances of those classes

or maybe some subsets of those.

These days I probably just call them

   (template) function objects (which work with result_of)

which is probably sufficient. However it might not be bad if someone
wants to go through the work of explicitly defining the relevent
"concepts" here.

I'm imagining something along the lines of

   concept BinaryResultOfCallable

   type F models BinaryResultOfCallable iff
      for some {f,x,y} (with types {F,X,Y})
         the expression "f(x,y)" is legal, and results in an object
         whose type is "result_of<F(X,Y)>::type"
  
   Examples:
      given: int foo( int x, int y ) { /* ... */ }
      "&foo" is a model of BinaryResultOfCallable

      The FC++ full functoid "map" is a model of BinaryResultOfCallable

Hmm. While writing this up, it occurred to be that in FC++, there are a
few places where the result_of type is maybe incorrect. For example,
   odd_list<int> oli;
   ... delay( oli ) ...
I think that maybe delay() here returns a
   const list<int>&
whereas result_of< delay_type( odd_list<int> ) >::type is
   list<int>
Hmm. Interesting how you can find such "bugs" just by trying to nail
down concepts.

Douglas, are you reading this? Given both
   http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html
and what we know about where typeof/decltype/etc. are headed in the
standardization process, should a function object that returns a
"const X&" declare its "result_of" to be "X" or "const X&"?

-- 
-Brian McNamara (lorgon_at_[hidden])

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