Boost logo

Boost :

From: Barry Revzin (barry.revzin_at_[hidden])
Date: 2021-03-28 17:37:18


 Hey all,

I spent this morning implementing views::zip using Boost.Lambda2 (because
views::zip requires writing lots of single-operator lambdas, so it fits the
problem quite well). You can see the implementation here:
https://godbolt.org/z/jcjdd3xeo

I ran into a few issues I wanted to point out.

First, several operators are missing. This is the standard library's fault
(it's weird that not even dereference is there). But if the standard
library isn't going to provide them, I figure Boost.Lambda2 should, since
these are probably going to come up so may as well just add a few more
lines of code and call it a day. I needed to define five: * (unary), ++ and
-- (prefix), +=, and -=.

Second, this library has name lookup issues. Here's a reduced example (
https://godbolt.org/z/z8oEqnTnG):

#include <
https://raw.githubusercontent.com/pdimov/lambda2/develop/include/boost/lambda2/lambda2.hpp
>

namespace N {
    struct Irrelevant { };
    void operator+(Irrelevant, Irrelevant);

    int plus_one(int i) {
        using namespace boost::lambda2;
        return (_1 + 1)(i);
    }
}

This doesn't compile. _1 + 1 finds the appropriately-named irrelevant
operator+ and stops there, and we never get to the operator+ in namespace
boost::lambda2.

Either the operators need to be put in namespace std::placeholders for ADL
(which seems naughty, but also seems like something the standard library
could potentially do?) or the library should provide its own placeholders.
That would lose the nice _1 name, but gain the ability to provide both []
and ().

Thanks for the library,

Barry


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk