Hi,

Chris 'Xenon' Hanson wrote:

I'm also looking for a STL expert who knows for_each, mem_fun and
bin1st better than I to tell me what I'm doing wrong on a piece of
GDAL code related to VPB. But that's a different issue. Anyone who
wants to point out my mistake, contact me privately and I'll send you
the code snippet that is eluding me.


I'm no expert, but what I do know is that tr1::function and tr1::bind are much easier to understand than the original variants. I've once made a little test app for myself that I attach.

jp

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

#include <iostream>
#include <cmath>

#include <boost/tr1/functional.hpp>
//#include <functional>

using namespace std;

class simple {
public:
	int clfunc(int a, int b) {
		return a*b;
	}
};

// Make a function object that takes two ints and returns an int
typedef std::tr1::function <int (int, int)> jpcallback;

int test1(int a, int b)
{
	return a+b;
}

int main(void)
{
	simple mysim;

	jpcallback cb1 = &test1;
    
    // make a function from the member function and use param 1 and 2.
    // bind allows one to make functions from other functions and allows swizzling of parameters
    // or even leaving out or adding paramters
	jpcallback cb2 = std::tr1::bind(std::tr1::mem_fn(&simple::clfunc), &mysim, _1, _2);

	std::cout << cb1(5,2) << "\n";
	std::cout << cb2(5,2) << "\n";
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to