Jason Fredrickson on 15 Aug 2003 17:27:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

RE: FW: [ALACPP] bound for success!


Honestly, I don't remember what Gavin's function was - I just read it as
pseudocode for any function which took an argument of the same type as
the contents of the source vector and returned the type of the
destination vector.  Apologies if I confused people by binding to the
wrong function type.

The bind in the example:

boost::bind(&aTransformationFunction, _1)

assumes that aTransformationFunction is a global (i.e. non-member)
function which takes a single argument.  If you were in OO land, and
wanted the transformation function to be called on a class, then (with
apologies for the massively noncompiling pseudocode):

class SomeObjectIWrote {
public:
	returnType aTransformationFunction(inputType arg) {
		// does some stuff; }
};

SomeObjectIWrote transformerObject;

std::transform(source.begin(), source.end(),
	std::back_inserter(dest),
	boost::bind(&SomeObjectIWrote::aTransformationFunction,
&transformerObject, _1));

Where the additional argument in bind links the function signature to
the particular object (by pointer).  Of course, by talking about bind
here, I'm basically sticking my neck out for Arlo to chop off, but those
are the dangers we face every day. :)

Now for my question: what the heck are unary and binary functions?  Does
this refer to the number of arguments?

Thanks,
Jason

Jason Fredrickson
Vice-President, Operations
Agile Solutions
Jason.Fredrickson@xxxxxxxxxxxx
(626) 644-7280
 


> -----Original Message-----
> From: alacpp-bounces@xxxxxxxxxxx 
> [mailto:alacpp-bounces@xxxxxxxxxxx] On Behalf Of Christopher Smith
> Sent: Friday, August 15, 2003 9:48 AM
> To: ALACPP Mailing List
> Subject: Re: FW: [ALACPP] bound for success!
> 
> 
> On Fri, 2003-08-15 at 09:22, Jason Fredrickson wrote:
> > Correct me if I'm wrong, but isn't this exactly what 
> std::transform is 
> > designed to let you do?  So you'd want something like:
> 
> Wow! I have never been shown the transform function before. I 
> always found it strange that STL had no analogue to collect. 
> Learn something new every day! :-)
> 
> The bind in your example seems a little off, as it looks like 
> it assumes aTransformationFunction is a binary function, but 
> Gavin's sample indicates it's unary. Am I missing something?
> 
> -- 
> Christopher Smith <x@xxxxxxxx> 
> _______________________________________________
> alacpp mailing list
> alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp
> 


_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp