468,457 Members | 1,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

make_transform_iterator and shared_ptr

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(),boo st::mem_fn(&A::value))
,boost::make_transform_iterator(dataset.end(),boos t::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>* ,
std::vector<boost::shared_ptr<A>, std::allocator<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<doubl e, A>,
__gnu_cxx::__normal_iterator<boost::shared_ptr<A>* ,
std::vector<boost::shared_ptr<A>, std::allocator<boost::shared_ptr<A>
>, boost::use_default, boost::use_default>' to non-scalar type
'__gnu_cxx::__normal_iterator<const boost::shared_ptr<A>*,
std::vector<boost::shared_ptr<A>, std::allocator<boost::shared_ptr<A>
>' requested Survival Survival_dist_impl_aggregate_test.cpp line
92 1200190279169 231939
Jan 13 '08 #1
8 3859
On Jan 13, 11:36 am, er <erwann.rog...@gmail.comwrote:
dataset_type::const_iterator e =
upper_bound(

boost::make_transform_iterator(dataset.begin(),boo st::mem_fn(&A::value))
,boost::make_transform_iterator(dataset.end(),boos t::mem_fn(&A::value))
,1.0
)
How about:

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

Regards,
Jan 13 '08 #2
er
On Jan 12, 11:52 pm, shunsuke <pstade...@gmail.comwrote:
On Jan 13, 11:36 am, er <erwann.rog...@gmail.comwrote:
dataset_type::const_iterator e =
upper_bound(
boost::make_transform_iterator(dataset.begin(),boo st::mem_fn(&A::value))
,boost::make_transform_iterator(dataset.end(),boos t::mem_fn(&A::value))
,1.0
)

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>* ,
std::vector<boost::shared_ptr<A>, std::allocator<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

Jan 13 '08 #3
On Jan 14, 12:03 am, er <erwann.rog...@gmail.comwrote:
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,
Jan 13 '08 #4
er
On Jan 13, 4:38 pm, shunsuke <pstade...@gmail.comwrote:
On Jan 14, 12:03 am, er <erwann.rog...@gmail.comwrote:
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,
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...
Jan 14 '08 #5
On Jan 14, 9:38 am, er <erwann.rog...@gmail.comwrote:
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...
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<Aconst &p) const { return p-
>value(); }
};

Regards,
Jan 14 '08 #6
er
On Jan 13, 8:16 pm, shunsuke <pstade...@gmail.comwrote:
On Jan 14, 9:38 am, er <erwann.rog...@gmail.comwrote:
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...

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<Aconst &p) const { return p-
value(); }
};

Regards,
Thanks again!

I meant class A_wrap{ public: /* A's functionality*/ private:
shared_ptr<Apimpl;}, just more straightforward to have
vector<A_wrapthan 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,
boost::_mfi::cmf0<double, A>, boost::_bi::list1<boost::arg<1(*)()>
>, __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


Jan 14 '08 #7
On Jan 15, 8:43 am, er <erwann.rog...@gmail.comwrote:
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,
Jan 15 '08 #8
er
On Jan 15, 5:37 am, shunsuke <pstade...@gmail.comwrote:
On Jan 15, 8:43 am, er <erwann.rog...@gmail.comwrote:
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,
Got it, thanks.
Jan 15 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ernst Murnleitner | last post: by
6 posts views Thread by Ryan Mitchley | last post: by
7 posts views Thread by myfavdepo | last post: by
14 posts views Thread by Tim H | last post: by
9 posts views Thread by Tim H | last post: by
4 posts views Thread by EnsGabe | last post: by
5 posts views Thread by .rhavin grobert | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.