C++ Logo

std-discussion

Advanced search

Re: std::apply and adl get

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Wed, 29 Sep 2021 11:22:31 +0200
Hi,

Il 28/09/21 18:37, Jordi Vilar via Std-Discussion ha scritto:
> 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.

This is in general an unsolved problem -- there isn't a way to
programmatically destructure a type. This affects std::apply, but also
other tuple-related functionality (make_from_tuple, tuple's assignment
operator, etc.).

Note that simply making those `get` calls perform ADL won't help in
every case where you can apply structured bindings. It won't work for
arrays, it won't work for non-destructurable classes (where you
destructure the accessible data members), and it also won't work for
destructurable classes that chose a member get() vs. a non-member one.

My 2 c,
-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2021-09-29 04:22:47