Boost logo

Boost Users :

Subject: Re: [Boost-users] Inconsistent behavior of fusion::find with vector and adapted struct.
From: Christopher Schmidt (mr.chr.schmidt_at_[hidden])
Date: 2009-08-05 23:47:07


I am pretty sure this is a bug. The cv-ness of a certain fusion type
should not be relevant in this particular case.

You can identify adapted structs by their fusion::struct_tag - tag.

-C.

Mike Tegtmeyer schrieb:
> I seem to have found an inconsistency in how fusion::find works with
> fusion::vector and an adapted struct. Basically, attempting to find a
> non-const type on a const vector with a non-const member works but
> requires a const-member find for an adapted struct. (See code below). Is
> this something that was just overlooked or there a technical reason for
> this behavior. In any case is there some way to identify a adapted
> struct in the general case (as apposed to the tag of the specific type)
> that can be used for a workaround?
>
> Thanks in advance,
> Mike
>
> #include <boost/fusion/adapted/struct/adapt_struct.hpp>
>
> #include <boost/fusion/container/vector/vector.hpp>
>
> #include <boost/fusion/algorithm/query/find.hpp>
>
>
> #include <boost/type_traits.hpp>
>
>
> #include <string>
>
> #include <iostream>
>
>
> namespace b = boost;
>
> namespace bf = boost::fusion;
>
>
> namespace demo
>
> {
>
> struct employee
>
> {
>
> std::string name;
>
> int age;
>
> };
>
> }
>
>
> // demo::employee is now a Fusion sequence
>
> BOOST_FUSION_ADAPT_STRUCT(
>
> demo::employee,
>
> (std::string, name)
>
> (int, age))
>
>
> int main(void)
>
> {
>
> typedef bf::vector<int,float> V1;
>
>
>
> // Find against non-const V1
>
> V1 v1(1,2.0);
>
>
> BOOST_MPL_ASSERT_NOT((
> b::is_same<bf::result_of::find<V1,int>::type,bf::result_of::end<V1>::type>
> ));
>
>
> assert(*bf::find<int>(v1) == 1);
>
>
>
> // Find against const V1
>
> const V1 const_v1(3,4.0);
>
>
> BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<const
> V1,int>::type,bf::result_of::end<const V1>::type> ));
>
>
> assert(*bf::find<int>(const_v1) == 3);
>
>
> // Find against non-const employee
>
> demo::employee e1 = {"Foo",18};
>
>
> BOOST_MPL_ASSERT_NOT((
> b::is_same<bf::result_of::find<demo::employee,int>::type,bf::result_of::end<demo::employee>::type>
> ));
>
>
> assert(*bf::find<int>(e1) == 18);
>
>
> // Find against const employee
>
> const demo::employee const_e1 = {"Bar",21};
>
>
> #if 0
>
> BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<const
> demo::employee,int>::type,bf::result_of::end<const
> demo::employee>::type> ));
>
>
> assert(*bf::find<int>(const_e1) == 21);
>
> #else
>
> // note that the find key is a const int for this to work and is
> inconsistent with fusion::vector
>
> BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<const
> demo::employee,const int>::type,bf::result_of::end<const
> demo::employee>::type> ));
>
>
> assert(*bf::find<const int>(const_e1) == 21);
>
> #endif
>
>
> return 0;
>
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net