|
Boost : |
From: Arash Partow (arash_at_[hidden])
Date: 2006-07-13 10:21:33
Hi all,
I'm having some difficulties getting the following piece of code to compile:
#include <iostream>
#include <vector>
#include <boost/utility.hpp>
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
class AClass
{
public:
AClass(){}
void b(int i, int j, int k)
{
std:: cout << "a::b() - " << i << "\t" << j << "\t" << k << std::endl;
}
};
template <typename T,int i> class select
{
public:
typedef typename boost::tuples::element<i,T>::type result_type;
template <typename U>
result_type operator()(const U& u) const
{
return u.get<i>();
}
};
int main(int argc, char* argv[])
{
typedef boost::tuples::tuple<AClass,int,int,int> param_set;
std::vector<param_set> list;
list.push_back(param_set(AClass(),1,2,3));
list.push_back(param_set(AClass(),2,3,4));
list.push_back(param_set(AClass(),3,4,5));
list.push_back(param_set(AClass(),4,5,6));
list.push_back(param_set(AClass(),5,6,7));
std::for_each(
list.begin(),
list.end(),
boost::bind(&AClass::b,
boost::bind(select<param_set,0>(),_0),
boost::bind(select<param_set,0>(),_1),
boost::bind(select<param_set,0>(),_2),
boost::bind(select<param_set,0>(),_3)));
return true;
}
Basically the "select class" is a code snippet I found on this list,
the compilation errors I believe exist in how I'm calling bind, but
I cant tell whats going wrong.
Also I'm wondering is there a better way of doing what I'm trying to
do, is there already a class or something in boost that will allow
one to bind a function and a tuples of parameters.
Also I'm wondering if it will be possible to derive AClass from
boost::noncopyable and still be able to instantiate class instances
as part of method parameters.
Any help would be very much appreciated.
Arash Partow
________________________________________________________
Be one who knows what they don't know,
Instead of being one who knows not what they don't know,
Thinking they know everything about all things.
http://www.partow.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk