how to compare fusion adapted structures

Hi, in my project I do have a lot of fusion adapted structures (due to use for/with spirit). Now I want to compare them. How to reuse the informations? In the example attached, I show the (imo) complicated way using fusion::vector_tie. I would like reuse the BOOST_FUSION_ADAPT_STRUCT macro since it generates tag_of<>, struct_member<>, struct_member_name<> , struct_size<> etc. At http://www.boost.org/doc/libs/1_42_0/libs/fusion/doc/html/fusion/extension/e... there is the full blown feature shown how to adapt the structure for a fusion iterator. What do I really need for simple comparing? Is it the way to use? Even simpler one? Since the project is involving, a simple and && combine of the members isn't save - easy to lost one ... Thanks, Olaf

Olaf Peter schrieb:
Hi,
in my project I do have a lot of fusion adapted structures (due to use for/with spirit).
Just a note aside: starting with release 1.43 you are able to define fusion sequences in situ. If you just need public attributes in your structs, without helper functions, you can probably save some typing. See http://www.boost.org/doc/libs/1_43_0/libs/fusion/doc/html/fusion/adapted/def... for more information.
Now I want to compare them. How to reuse the informations? In the example attached, I show the (imo) complicated way using fusion::vector_tie. I would like reuse the BOOST_FUSION_ADAPT_STRUCT macro since it generates tag_of<>, struct_member<>, struct_member_name<> , struct_size<> etc.
fusion::equal_to or fusion::operator== (defined in
At http://www.boost.org/doc/libs/1_42_0/libs/fusion/doc/html/fusion/extension/e... there is the full blown feature shown how to adapt the structure for a fusion iterator. What do I really need for simple comparing? Is it the way to use? Even simpler one? [snip]
Adapting a class-type includes generation of the necessary boilerplate for iteration. In fact, there should not be any difference between one of the provided random access sequences (such as fusion::vector) and an adapted sequence. -Christopher

in my project I do have a lot of fusion adapted structures (due to use for/with spirit).
Just a note aside: starting with release 1.43 you are able to define fusion sequences in situ. If you just need public attributes in your structs, without helper functions, you can probably save some typing. See
really cool, thanks. Using it, I've got a Segmentation fault. Got something wrong? Thanks, Olaf

Olaf Peter schrieb:
in my project I do have a lot of fusion adapted structures (due to use for/with spirit).
Just a note aside: starting with release 1.43 you are able to define fusion sequences in situ. If you just need public attributes in your structs, without helper functions, you can probably save some typing. See
really cool, thanks. Using it, I've got a Segmentation fault. Got something wrong?
BOOST_FUSION_DEFINE_STRUCT( (), foo, (std::string, a) (std::string, b) ) should be BOOST_FUSION_DEFINE_STRUCT( BOOST_PP_EMPTY(), foo, (std::string, a) (std::string, b) ) . Other than that, you did not include <string> . I am pretty sure your compiler did not find an adequate operator== for std::string. The compiler should have printed an error though. Which one are you using? -Christopher

El 06/05/2010 02:04 p.m., Olaf Peter escribió:
bool operator==( const foo& lhs, const foo& rhs ) { return lhs == rhs; }
Unless I'm missing something, this looks like infinite recursion, which would cause stack overflow. Don't you get a warning from your compiler? Agustín K-ballo Bergé.- http://talesofcpp.blogspot.com

Agustín K-ballo Bergé schrieb:
El 06/05/2010 02:04 p.m., Olaf Peter escribió:
bool operator==( const foo& lhs, const foo& rhs ) { return lhs == rhs; }
Unless I'm missing something, this looks like infinite recursion, which would cause stack overflow. Don't you get a warning from your compiler?
yes, that is it (over right I came to the same result). Here, this works: bool operator==( const foo& lhs, const foo& rhs ) { return fusion::equal_to( lhs, rhs ); } fusion::operator==( lhs, rhs ) won't compile fusion_tie.cpp: In function ‘bool operator==(const<unnamed>::foo&, const<unnamed>::foo&)’: fusion_tie.cpp:18: error: no matching function for call to ‘operator==(const<unnamed>::foo&, const<unnamed>::foo&)’ I've got no warning from gcc version 4.4.1 (no extra Warning option). Thanks, Olaf
participants (3)
-
Agustín K-ballo Bergé
-
Christopher Schmidt
-
Olaf Peter