Ticket #5811 (closed Bugs: fixed)

Opened 6 years ago

Last modified 3 years ago

indirected range adaptor not satisfied with unary dereference operator

Reported by: Lars Viklund <zao@…> Owned by: neilgroves
Milestone: To Be Determined Component: range
Version: Boost Development Trunk Severity: Problem
Keywords: optional element_type range adaptor indirected Cc:


The documentation for Range's indirected adaptor claims that it is usable with anything that has an unary operator*().

When using it with a range of optional<int>, it seems to require an element_type inner type, which optional doesn't expose and the docs does not require.

The following testcase fails to compile with VC10 and GCC 4.2.3:

#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <vector>

int main(int argc, char* argv[])
        std::vector<boost::optional<int> > v;
        v | boost::adaptors::indirected;


Change History

comment:1 Changed 6 years ago by Lars Viklund <zao@…>

This was apparently known back in May in a question on Stack Overflow, which also mentions a workaround for Boost.Optional. It doesn't address the underlying doc bug though, so the ticket is still valid.

#include <boost/optional/optional_fwd.hpp>
#include <boost/pointee.hpp>

namespace boost
    template<typename P>
    struct pointee<optional<P> >
        typedef typename optional<P>::value_type type;

comment:2 Changed 6 years ago by Júlio Hoffimann Mendes <julio.hoffimann@…>

I found this related topic on stackoverflow:

The first answer solved the problem for me, i don't know if it's safe though.

Regards, Júlio.

comment:3 Changed 3 years ago by neilgroves

  • Status changed from new to closed
  • Resolution set to fixed

Added a unit test to confirm that a fix has been made to Boost.Optional and that the use-case now works as expected when using optional with the indirected adapter.


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.