|
Boost Users : |
Subject: [Boost-users] [range] multiple adaptors on sequense
From: Sam Fisher (infest21h_at_[hidden])
Date: 2010-11-03 09:11:46
Hello,
Is it possible to apply multiple adaptors to a range-base sequence?
Is looks like possible for simple types:
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/range/adaptor/uniqued.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/assign.hpp>
using boost::assign::operator +=;
#include <boost/spirit/home/phoenix.hpp>
namespace phx = boost::phoenix;
int square(int val)
{
return val * val;
}
int range_test_simple()
{
typedef std::vector<int> V;
V source;
source += 1,1,1,2,2,2,3,3,3,4;
using namespace boost::adaptors;
V result;
boost::push_back(result, source | transformed(&square)); // Ok
boost::push_back(result, source | uniqued); // Ok
boost::push_back(result, source | transformed(&square) | uniqued); // Ok
boost::push_back(result, source | uniqued | transformed(&square)); // Ok
return 0;
}
but how about this? (source is continued...)
struct Foo
{
Foo(const std::string& name, int value) : name_(name), value_(value)
{
}
std::string name_;
int value_;
};
typedef boost::shared_ptr<Foo> FooPtr;
int range_test_complex()
{
typedef std::vector<FooPtr> V;
V source;
source +=
boost::make_shared<Foo>("Foo", 10),
boost::make_shared<Foo>("Bar", 20),
boost::make_shared<Foo>("Baz", 30),
boost::make_shared<Foo>("Baz", 30) // duplicate is here
;
std::vector<std::string> result1;
std::vector<int> result2;
using namespace boost::adaptors;
using phx::arg_names::arg1;
boost::push_back(result1, source | transformed(phx::bind(&Foo::name_,
*arg1)) | uniqued); // Fails
boost::push_back(result2, source | transformed(phx::bind(&Foo::value_,
*arg1)) | uniqued); // Fails
return 0;
}
What I'm doing wrong?
I use MSVS 2010 and boost trunk.
Thanks,
Sam
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