Modify

Opened 6 years ago

Closed 4 years ago

#5811 closed Bugs (fixed)

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:

Description

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 (3)

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:

http://stackoverflow.com/questions/6123327/use-boostoptional-together-with-boostadaptorsindirected

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Neil Groves.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.