C++ Logo


Advanced search

Re: std::apply and adl get

From: Peter Sommerlad (C++) <"Peter>
Date: Tue, 28 Sep 2021 21:21:11 +0200
As the author of the initial spec for apply (after its implementation
was available as an example in the standard, I think that when apply was
specified, structured bindings weren't invented yet, and nobody thought
about applying apply to something that is not a tuple. I would say that
structured bindings were the reason to expand the possibilities to
non-tuples and allowing therefore the customization.

So the first question, what is your use case? and why? Is it just for
symmetry? Or is there something useful.


Jordi Vilar via Std-Discussion wrote on 28.09.21 18:37:
> Hi everyone,
> Both structured binding and `std::apply` are two different ways to
> accomplish a quite similar function. And both make use of similar
> tools: `std::tuple_size`, `std::tuple_element` and `get`, but `get` is
> found via ADL in structured binding and found via `std::` namespace
> qualification in `std::apply`. Is this difference really intended?
> I understand that it is legal to specialize `std::tuple_size` and
> `std::tuple_element`, but it's not legal to create additional
> overloads for `get` in the `std` namespace. The net result is that I
> can expose my custom classes as structured binding friendly, but not
> `std::apply`-friendly.
> Maybe is there a preference for ADL in language features
> (`begin`/`end` in for-range-loop, `get` in structured binding) but not
> in library features? Should it be reported as a deffect? (changing
> `std::apply` to use `get` by ADL shouldn't break anything)
> Thanks in advance for your comments,
> Jordi

Peter Sommerlad
Better Software: Consulting, Training, Reviews
Modern, Safe & Agile C++
+41 79 432 23 32

Received on 2021-09-28 14:21:20