473,232 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

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 4091
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ernst Murnleitner | last post by:
Hello, in 2 other threads I had questions partly related to shared_ptr. I changed my normal pointers to a class to shared_ptr. (i.e. boost::shared_ptr). I thought, the use of shared_ptr is...
6
by: Ryan Mitchley | last post by:
Hi all Given bool bResult; shared_ptr<cSampleData> pNewData; shared_ptr<cBase> pNewBase; where cSampleData is descended from cBase, the following gives me a valid pNewData to the correct...
14
by: PengYu.UT | last post by:
In the following program, I want an iterator contain pointer pointing to constant object not const pointer. If it is possible would you please let me know how to do it? #include...
7
by: myfavdepo | last post by:
Hi all, I have a query regarding the exchanging of a boost::shared_ptr beween different threads. In my program i've two threads both of which having their own internal queues for storing the...
14
by: Tim H | last post by:
I understand the semantics of why this works the way it does. But I wonder if there's a reason for the behaviore at the line marked "QUESTION". I figured if there is an answer, someone here knows...
9
by: Tim H | last post by:
Why is the following code not valid? I mean, I see the code and it doesn't allow it, but I am curious about the rationale? boost::shared_ptr<intpi = new int; pi = new int; Thanks Tim
4
by: EnsGabe | last post by:
Suppose you have a class heirarchy as such: class Base{ .... }; class Mid1 : public Base{ ....
5
by: Fokko Beekhof | last post by:
Hello all, please consider the following code: -------------------------------------------------- #include <tr1/memory> struct BaseA { int x;
5
by: .rhavin grobert | last post by:
are there any pro's and con's in using references to shared_ptr<>'s ? example: __________________________________________________ void obj::foo(shared_ptr<>); vs. void...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.