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
#include
#include
#include
#include
#include
using boost::assign::operator +=;
#include
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::vectorstd::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