make_transform_iterator and shared_ptr

E

er

Hi All, could anyone make a suggestion to fix the code below? Thanks!


class A{
public:
/* constructor */
double value()const{/* implementation */};
};

typedef std::vector<boost::shared_ptr<A> > dataset_type;
dataset_type dataset;
/* fill A*/

dataset_type::const_iterator e =
upper_bound(

boost::make_transform_iterator(dataset.begin(),boost::mem_fn(&A::value))
,boost::make_transform_iterator(dataset.end(),boost::mem_fn(&A::value))
,1.0
);

Severity and Description Path Resource Location Creation Time Id
/usr/include/c++/4.1.3/bits/stl_algo.h instantiated from
'_ForwardIterator std::upper_bound(_ForwardIterator, _ForwardIterator,
const _Tp&) [with _ForwardIterator =
boost::transform_iterator<boost::_mfi::cmf0<double, A>,
__gnu_cxx::__normal_iterator<boost::shared_ptr<A>*,
, boost::use_default, boost::use_default>, _Tp = double]'
Survival line 2886 1200190279169 231940


Severity and Description Path Resource Location Creation Time Id
/usr/local/boost_1_34_1/boost/iterator/transform_iterator.hpp error:
no matching function for call to 'boost::_mfi::cmf0<double,
A>::cmf0()' Survival line 100 1200190279170 231941

Severity and Description Path Resource Location Creation Time Id
error: conversion from
'boost::transform_iterator<boost::_mfi::cmf0<double, A>,
__gnu_cxx::__normal_iterator<boost::shared_ptr<A>*,
'__gnu_cxx::__normal_iterator<const boost::shared_ptr<A>*,
92 1200190279169 231939
 
S

shunsuke

dataset_type::const_iterator e =
upper_bound(

boost::make_transform_iterator(dataset.begin(),boost::mem_fn(&A::value))
,boost::make_transform_iterator(dataset.end(),boost::mem_fn(&A::value))
,1.0
)

How about:

e = upper_bound(...).base();

Regards,
 
E

er

How about:

e = upper_bound(...).base();

Regards,

Thanks for your help: I have one less error.

But I have 2 errors remaining:

Severity and Description Path Resource Location Creation Time Id
/usr/include/c++/4.1.3/bits/stl_algo.h instantiated from
'_ForwardIterator std::upper_bound(_ForwardIterator, _ForwardIterator,
const _Tp&) [with _ForwardIterator =
boost::transform_iterator<boost::_mfi::cmf0<double, A>,
__gnu_cxx::__normal_iterator<boost::shared_ptr<A>*,
, boost::use_default, boost::use_default>, _Tp = double]'
Survival line 2886 1200236373397 231961

Severity and Description Path Resource Location Creation Time Id
/usr/local/boost_1_34_1/boost/iterator/transform_iterator.hpp error:
no matching function for call to
'boost::_mfi::cmf0<double,A>::cmf0()' Survival line 100 1200236373397
231962
 
S

shunsuke

Survival line 2886 1200236373397 231961

Severity and Description Path Resource Location Creation Time Id
/usr/local/boost_1_34_1/boost/iterator/transform_iterator.hpp error:
no matching function for call to
'boost::_mfi::cmf0<double,A>::cmf0()' Survival line 100 1200236373397
231962

Probably understood.
std::upper_bound needs ForwardIterator, which must be
DefaultConstructible.
But boost::mem_fn(..) is not.
So that, transform_iterator containing boost::mem_fn(..) is not.
Ditto boost::bind.
There seems no trivial workaround.

Regards,
 
E

er

Probably understood.
std::upper_bound needs ForwardIterator, which must be
DefaultConstructible.
But boost::mem_fn(..) is not.
So that, transform_iterator containing boost::mem_fn(..) is not.
Ditto boost::bind.
There seems no trivial workaround.

Regards,

Thanks!

What if I create a Pimpl that wraps around shared_ptr<A>? I guess I
won't need mem_fn anymore. Will go ahead and try that a bit later but
in someone wishes to comment...
 
S

shunsuke

Thanks!

What if I create a Pimpl that wraps around shared_ptr<A>? I guess I
won't need mem_fn anymore. Will go ahead and try that a bit later but
in someone wishes to comment...

Though I don't understand what your Pimpl means,
a non-generic but simple workaround is to write a function-object from
scratch.

struct call_A_value
{
typedef A_value_result_type result_type;
result_type operator()(shared_ptr said:
value(); }
};

Regards,
 
E

er

Though I don't understand what your Pimpl means,
a non-generic but simple workaround is to write a function-object from
scratch.

struct call_A_value
{
typedef A_value_result_type result_type;

};

Regards,

Thanks again!

I meant class A_wrap{ public: /* A's functionality*/ private:
shared_ptr<A> pimpl;}, just more straightforward to have
vector<A_wrap> than vector<shared_ptr<A> >, so I have modified
call_A_value accordingly (return ref.value() rather than p->value()).
Your suggestion works, but I'm unclear why I can't instead use
bind(&A_wrap::value,_1)?

Severity and Description Path Resource Location Creation Time Id
error: no matching function for call to
'upper_bound(boost::transform_iterator<boost::_bi::bind_t<double,
, __gnu_cxx::__normal_iterator<A*, std::vector<A, std::allocator<A> >
, boost::use_default, boost::use_default>,
boost::transform_iterator<A_call_entry_time,
__gnu_cxx::__normal_iterator<A*, std::vector<A, std::allocator<A> > >,
boost::use_default, boost::use_default>, double)' Survival
Survival_dist_impl_aggregate_test.cpp line 94 1200353623364 233605
 
S

shunsuke

Your suggestion works, but I'm unclear why I can't instead use
bind(&A_wrap::value,_1)?

A FunctionObject which boost::bind(and mem_fn) returns is not
DefaultConstructible,
which ForwardIterator(and its algorithms) requires.


Regards,
 
E

er

A FunctionObject which boost::bind(and mem_fn) returns is not
DefaultConstructible,
which ForwardIterator(and its algorithms) requires.

Regards,

Got it, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top