boost::bind with boost::fusion::for_each

M

Mark

Hi folks, given:

#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/include/algorithm.hpp>
#include <boost/fusion/include/vector.hpp>

#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/next_prior.hpp>

#include <boost/fusion/mpl.hpp>
#include <boost/fusion/adapted.hpp>
#include <boost/array.hpp>

#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/include/value_at.hpp>

// boost::fusion::result_of::size
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/include/size.hpp>

// boost::fusion::at
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/at.hpp>

# include <boost/bind.hpp>

# include <iostream>
# include <vector>
# include <typeinfo>
# include <cstdio>

typedef std::vector < int > INT_VEC ;
typedef boost::array<int, 100> array_t;

struct my_struct {
int i;
bool j;
boost::array<int, 100> arr1;
INT_VEC vv ;
my_struct()
: vv ( 100 )
{}
};


BOOST_FUSION_ADAPT_STRUCT(
my_struct,
(int, i)
(bool, j)
(array_t, arr1 )
(INT_VEC, vv)
)

struct display_ {
typedef void result_type ;
template <typename T>
result_type operator()(T& t) const {
printf(" --%s-- \n", typeid(t).name());
parse(t);
}

void parse(int & f) { std::cout << f << std::endl; };
void parse(char & f) {};
void parse(bool & f) { std::cout << f << std::endl; };
void parse(array_t & f) {
for(int i = 0; i < 100; ++i)
std::cout << f << std::endl;
}
void parse(INT_VEC & f) {
for(int i = 0; i < 100; ++i)
std::cout << f << std::endl;
}
//another function...
};

class foo {
my_struct f;
display_ dt;
public :
foo()
{}
void work () {
boost::fusion::for_each(f, boost::bind ( display_(), &dt, _1 ) );
//dt.
}

};

int main() {

foo f;
f.work() ;

}

How do I invoke bind on display_::eek:perator()?

boost::bind ( display_(), &dt, _1 ): produce the compiler (MSVC 2010) error:
'error C2780: 'display_::result_type display_::eek:perator ()(T &) const' : expects 1 arguments - 2 provided'
 
J

Jeff Flinn

Hi folks, given:

#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/include/algorithm.hpp>
#include <boost/fusion/include/vector.hpp>

#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/next_prior.hpp>

#include <boost/fusion/mpl.hpp>
#include <boost/fusion/adapted.hpp>
#include <boost/array.hpp>

#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/include/value_at.hpp>

// boost::fusion::result_of::size
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/include/size.hpp>

// boost::fusion::at
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/at.hpp>

# include <boost/bind.hpp>

# include <iostream>
# include <vector>
# include <typeinfo>
# include <cstdio>

typedef std::vector < int > INT_VEC ;
typedef boost::array<int, 100> array_t;

struct my_struct {
int i;
bool j;
boost::array<int, 100> arr1;
INT_VEC vv ;
my_struct()
: vv ( 100 )
{}
};


BOOST_FUSION_ADAPT_STRUCT(
my_struct,
(int, i)
(bool, j)
(array_t, arr1 )
(INT_VEC, vv)
)

struct display_ {
typedef void result_type ;
template <typename T>
result_type operator()(T& t) const {
printf(" --%s-- \n", typeid(t).name());
parse(t);
}

void parse(int & f) { std::cout << f << std::endl; };
void parse(char & f) {};
void parse(bool & f) { std::cout << f << std::endl; };
void parse(array_t & f) {
for(int i = 0; i < 100; ++i)
std::cout << f << std::endl;
}
void parse(INT_VEC & f) {
for(int i = 0; i < 100; ++i)
std::cout << f << std::endl;
}
//another function...
};

class foo {
my_struct f;
display_ dt;
public :
foo()
{}
void work () {
boost::fusion::for_each(f, boost::bind ( display_(), &dt, _1 ) );
//dt.
}

};

int main() {

foo f;
f.work() ;

}

How do I invoke bind on display_::eek:perator()?

boost::bind ( display_(), &dt, _1 ): produce the compiler (MSVC 2010) error:
'error C2780: 'display_::result_type display_::eek:perator ()(T &) const' : expects 1 arguments - 2 provided'


There shouldn't be a need for bind, since dt is a function object,
doesn't this work:

boost::fusion::for_each(f, dt );

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,183
Members
46,719
Latest member
login dogas.info

Latest Threads

Top