specify a functor-object^functor-type

Sometimes [1] you plug in a functor object; sometimes [2] you plug in a functor type into a template.

In [2], I confirmed that concretized class’s would instantiate a functor object. In short, you specify functor TYPE only– instantiation is implicit. Note a template usually specifies a type param. A function type meets the requirement; a functor object doesn’t.

(I seldom see a template with a NDTTP like “int” — kind of wizardry.)

[1] In the first case you usually have a regular function, not a template

One use case of functor-object-passing (pbclone) is a STL algorithm like

 class myLess {/*....*/};

 std::sort(V.begin(), V.end(), myLess()); // which is short version of

 std::sort <vector ::iterator, // 1st concrete type
               myLess // 2nd concrete type
           > //now we have a concretized function. Below are 3 args:
   (V.begin(), V.end(), myLess()); // ctor args

In this case, the functor instantiation is fairly explicit.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s