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
#include
#include
#include
#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 V1;
// Find against non-const V1
V1 v1(1,2.0);
BOOST_MPL_ASSERT_NOT((
b::is_same::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
::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_samedemo::employee,int::type,bf::result_of::enddemo::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::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::type,bf::result_of::end<const demo::employee>::type> ));
assert(*bf::find<const int>(const_e1) == 21);
#endif
return 0;
}