Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > boost::bind with boost::fusion::for_each

Reply
Thread Tools

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

 
 
Mark
Guest
Posts: n/a
 
      11-22-2012
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[i] << std::endl;
}
void parse(INT_VEC & f) {
for(int i = 0; i < 100; ++i)
std::cout << f[i] << 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_:perator()?

boost::bind ( display_(), &dt, _1 ): produce the compiler (MSVC 2010) error:
'error C2780: 'display_::result_type display_:perator ()(T &) const' : expects 1 arguments - 2 provided'
 
Reply With Quote
 
 
 
 
Jeff Flinn
Guest
Posts: n/a
 
      11-25-2012
On 11/21/2012 11:14 PM, Mark wrote:
> 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[i] << std::endl;
> }
> void parse(INT_VEC & f) {
> for(int i = 0; i < 100; ++i)
> std::cout << f[i] << 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_:perator()?
>
> boost::bind ( display_(), &dt, _1 ): produce the compiler (MSVC 2010) error:
> 'error C2780: 'display_::result_type display_: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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments