Opened 9 years ago

#8608 new Bugs

Default lambda expression with mpl::equal

Reported by: Louis Dionne <ldionne.2@…> Owned by: Aleksey Gurtovoy
Milestone: To Be Determined Component: mpl
Version: Boost Development Trunk Severity: Problem
Keywords: default lambda mpl equal Cc:

Description

Summary of the original message posted on the mailing list:


Some higher order algorithms in the MPL have a default for the lambda expression they accept. A good example is boost::mpl::equal:

    template <typename S1, typename S2, typename Pred = is_same<_, _> >
    struct equal;

This works fine most of the time, but I was recently bitten by the following:

    template <typename VectorOfVectors, typename Vector>
    struct find_vector
        : find_if<
            VectorOfVectors, equal<Vector, _1>
        >
    { };

    typedef find_vector<
        vector<
            vector<int, int>,
            vector<char, char>
        >,
        vector<char, char>
    >::type ThisWillBreak;

What happens here is that the equal<Vector, _1> expression inside find_vector really is equal<Vector, _1, is_same<_1, _2> > because of the default value for the predicate to equal. When the lambda is evaluated, the placholders inside the inner is_same<_1, _2> expression are replaced too, which yields unexpected results.


Original thread: http://thread.gmane.org/gmane.comp.lib.boost.devel/241690

Attachments (1)

default_lambda_args.diff (6.1 KB ) - added by Louis Dionne <ldionne.2@…> 9 years ago.
Test case, code fix and documentation change.

Download all attachments as: .zip

Change History (1)

by Louis Dionne <ldionne.2@…>, 9 years ago

Attachment: default_lambda_args.diff added

Test case, code fix and documentation change.

Note: See TracTickets for help on using tickets.