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.
}