|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-09-29 06:14:55
Alexander Borghgraef <alexander.borghgraef.rma_at_[hidden]> writes:
> But it is possible to do input with an indirect_iterator no? I mean,
> there's the example from the documentation (somewhat summarized):
Try compiling and running the example, then try compiling and running
your "somewhat summarized" version. Notice anything? When your
version crashes, it will reveal to you the important things you left
out: our example initializes all those pointers to refer to valid
locations first.
> char* pointers_to_chars[N];
> char* pointers_to_mutable_chars[N];
>
> boost::indirect_iterator<char* const*>
> mutable_indirect_first(pointers_to_mutable_chars),
> mutable_indirect_last(pointers_to_mutable_chars + N);
> boost::indirect_iterator<char* const*, char const>
> const_indirect_first(pointers_to_chars),
> const_indirect_last(pointers_to_chars + N);
>
> std::transform(const_indirect_first, const_indirect_last,
> mutable_indirect_first, std::bind1st(std::plus<char>(), 1));
>
> And this is the error message:
>
> /usr/include/boost/shared_ptr.hpp:247: typename
> boost::detail::shared_ptr_traits<T>::reference
> boost::shared_ptr<T>::operator*() const
> [with T = double]: Assertion `px != 0' failed.
Right; that's not a crash. It's an assertion.
> I must say it's all a bit beyond me right now. Could you explain why
> things go wrong here?
indirect_iterator doesn't automagically create the things the pointers
are supposed to be referring to, and dereferencing a NULL pointer is
illegal.
HTH,
-- Dave Abrahams Boost Consulting www.boost-consulting.com
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