Opened 6 years ago

Last modified 3 months ago

#5811 reopened Bugs

indirected range adaptor not satisfied with unary dereference operator

Reported by: Lars Viklund <zao@…> Owned by: Neil Groves
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;

Attachments (0)

Change History (4)

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 4 years ago by Neil Groves

Resolution: fixed
Status: newclosed

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.

comment:4 Changed 3 months ago by rob.desbois@…

Resolution: fixed
Status: closedreopened

This doesn't appear to be fixed; I've tried the testcase using the latest Boost (1.65.1) with both clang 4.01 and gcc 6.4.1, but still get the compilation failure:

boost_1_65_1/boost/pointee.hpp:30:27: error: no type named 'element_type' in 'boost::optional<int>'

Modify Ticket

Change Properties
Set your email in Preferences
as reopened The owner will remain Neil Groves.

Add Comment

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

Note: See TracTickets for help on using tickets.