Boost.Lambda2 usage

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Boost.Lambda2 usage

Boost - Dev mailing list
 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost.Lambda2 usage

Boost - Dev mailing list
On Sun, Mar 28, 2021 at 10:50 AM Barry Revzin via Boost <
[hidden email]> wrote:
> 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);
>     }
> }

To successfully compile, this has to be:

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

Note that it will not work if you say "using namespace boost::lambda2", you
have to bring in each individual operator you need.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost.Lambda2 usage

Boost - Dev mailing list
On Sun, Mar 28, 2021 at 2:26 PM Emil Dotchevski via Boost <
[hidden email]> wrote:

> On Sun, Mar 28, 2021 at 10:50 AM Barry Revzin via Boost <
> [hidden email]> wrote:
> > 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);
> >     }
> > }
>
> To successfully compile, this has to be:
>
> int plus_one(int i) {
>     using namespace std::placeholders;
>     using boost::lambda2::operator+;
>     return (_1 + 1)(i);
> }
>
> Note that it will not work if you say "using namespace boost::lambda2", you
> have to bring in each individual operator you need.
>

Yes, I understand all of that. But the point of this library is to provide
terse syntax for simple lambda expressions, and having to write
using-declarations for each operator in each scope that they are intended
to be used defeats the purpose.

Barry

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Boost.Lambda2 usage

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
niedz., 28 mar 2021 o 21:26 Emil Dotchevski via Boost <[hidden email]>
napisaƂ(a):

> On Sun, Mar 28, 2021 at 10:50 AM Barry Revzin via Boost <
> [hidden email]> wrote:
> > 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);
> >     }
> > }
>
> To successfully compile, this has to be:
>
> int plus_one(int i) {
>     using namespace std::placeholders;
>     using boost::lambda2::operator+;
>     return (_1 + 1)(i);
> }
>
> Note that it will not work if you say "using namespace boost::lambda2", you
> have to bring in each individual operator you need.
>

But is this how we recommend the library should be used?

Regards,
&rzej;


> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost