Boost logo

Boost Users :

Subject: [Boost-users] [Fusion] Views of Associative Sequences
From: James Knight (james.nate.knight_at_[hidden])
Date: 2009-10-15 15:27:37


I'm trying to find a solution to the following problem. If I have an
associative sequence such as a fusion::set
and I make a filter view of it, the view is not a model of an associative
sequence and does not support the
has_key and at_key functions. I can use fusion::as_set on the view to get
an associative sequence again, but
this doesn't really have the effect I want as it results in a set holding
copies of the original data whereas the
view referenced the original data. Example below.

Would it be possible to create a view which supported the associative
sequence interface? Any suggested alternative approaches?

Thanks
Nate

~~~~~~~~~~~~~~~~~

#include <boost/fusion/include/set.hpp>
#include <boost/fusion/include/intrinsic.hpp>
#include <boost/fusion/include/filter_view.hpp>
#include <string>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/mpl/placeholders.hpp>

namespace fusion = boost::fusion;
using boost::mpl::_;

int main()
{
    typedef fusion::set<int,double,std::string> set_t;
    set_t s(1,2.0,"hello");

    fusion::filter_view<set_t,boost::is_arithmetic<_>> filtered_view(s);
    fusion::front(filtered_view) = 4; //modifies s

fusion::result_of::as_set<fusion::filter_view<set_t,boost::is_arithmetic<_>
> >::type filtered_set(filtered_view);
    fusion::at_key<int>(filtered_set) = 16; // modifies the copied data in
filtered_set.
}



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