Boost logo

Boost :

From: Richard Hodges (hodges.r_at_[hidden])
Date: 2021-03-24 13:36:34


My review.

   - What is your evaluation of the design?

Extremely simple, solving a very narrow use case.

   - What is your evaluation of the implementation?

Unimpeachable. There isn't much to get wrong in 79 lines of code.

   - What is your evaluation of the documentation?

Describes the capabilities of the library perfectly clearly.

   - What is your evaluation of the potential usefulness of the library?

Since c++14, I have not seen a use case for any library implementations of
lambdas or std::bind at all.

   - Did you try to use the library? With which compiler(s)? Did you
     have any problems?

Yes, gcc. No issues.

   - How much effort did you put into your evaluation? A glance? A quick
     reading? In-depth study?

I ignored the simple use cases in the documentation and decided to see if I
could make the library do something more interesting. See below.

   - Are you knowledgeable about the problem domain?

Yes

Analysis:

To begin with I wrote a simple function involving c++ lambdas that did not
do arithmetic:

int main1() {
  auto source = std::vector{"the"s, "cat"s, "sat"s, "on"s, "the"s, "mat"s};
  auto dest = decltype(source)(source.size());

  std::transform(source.begin(), source.end(), dest.begin(), [](auto _1) {
    for (auto &c : _1)
      c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
    return _1;
  });

  std::for_each(dest.begin(), dest.end(), [sep = ""](auto &&x) mutable {
    std::cout << sep << x;
    sep = ", ";
  });
  std::cout << std::endl;
  return 0;
}

The salient part is the transform, but I will comment on the printing of
the result later.

I wondered whether it would be possible to express this transform in terms
of boost::lambda2.
What I really wanted to be able to write was this:
std::transform(source.begin(), source.end(), dest.begin(), uppercase(_1));

However, this is not possible since lambda2 leverages only
arithmetic operators.
So I settled on this:

 std::transform(source.begin(), source.end(), dest.begin(), uppercase < _1);

Then I added some boilerplate, which I was able to implement in terms of
lambda2:

constexpr struct uppercase_t {
} uppercase;

template <class C>
concept character =
    std::is_same_v<C, char> || std::is_same_v<C, unsigned char> ||
    std::is_same_v<C, signed char>;

template <character C> C operator<(uppercase_t, C x) {
  return
static_cast<C>(std::toupper(static_cast<std::make_unsigned_t<C>>(x)));
}

template <class C, class Traits, class Alloc>
std::string operator<(uppercase_t, std::basic_string<C, Traits, Alloc> x) {
  std::transform(x.begin(), x.end(), x.begin(), uppercase < _1);
  return x;
}

If we ignore the fact that I had to create a user-defined keyword and a
mini DSL, So far so good.

Then I wanted to see if I could implement the comma-separated output using
boost.lambda2.

Alas, no. I lost interest after realising it was going to take some serious
work.

At this point I was presented with a dilemma.
On the one hand, the library is concise, correct, limited in scope and well
documented.
On the other, it doesn't do anything other than remove a few keystrokes in
the rare case that I want a lambda to do some adding up or taking away.

On the one hand I am reluctant to vote against a library that some may find
pleasing or useful. On the other, I will never use this library.

Perhaps the author could provide some insight as to future plans or
extensions that would make the library more compelling for me?

On Mon, 22 Mar 2021 at 03:36, Joel de Guzman via Boost <
boost_at_[hidden]> wrote:

> The Boost formal review of the Lambda2, authored by Peter Dimov,
> starts Monday, March 22, 2021 to March 31, 2021 (inclusive).
>
> Documentation: https://pdimov.github.io/lambda2/doc/html/lambda2.html
> Source: https://github.com/pdimov/lambda2/
>
> Lambda2 is a simple, but functional, C++14 lambda library. It takes
> advantage
> of the fact that the standard <functional> header already provides
> placeholders
> _1, _2, _3, and so on, for use with std::bind, and function objects such
> as std::plus, std::greater, std::logical_not, and std::bit_xor,
> corresponding to
> arithmetic, relational, logical and bitwise operators.
>
> Please provide in your review information you think is valuable to
> understand your choice to ACCEPT or REJECT including Lambda2 as a
> Boost library. Please be explicit about your decision (ACCEPT or REJECT).
>
> Some other questions you might want to consider answering:
>
> - What is your evaluation of the design?
> - What is your evaluation of the implementation?
> - What is your evaluation of the documentation?
> - What is your evaluation of the potential usefulness of the library?
> - Did you try to use the library? With which compiler(s)? Did you
> have any problems?
> - How much effort did you put into your evaluation? A glance? A quick
> reading? In-depth study?
> - Are you knowledgeable about the problem domain?
>
> More information about the Boost Formal Review Process can be found
> at: http://www.boost.org/community/reviews.html
>
> The review is open to anyone who is prepared to put in the work of
> evaluating and reviewing the library. Prior experience in contributing to
> Boost reviews is not a requirement.
>
> Thank you for your efforts in the Boost community. They are very much
> appreciated.
>
> Peter is often available in the CppLang Slack #boost channel should you
> require any clarification not covered by the documentation. I am not
> frequently
> available in the Slack channel, but I'll certainly pay attention to the
> discussions.
> Please don't hesitate to ping me if needed.
>
> Cheers,
> --Joel de Guzman
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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