Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2024-12-06 14:48:36


Andrey Semashev wrote:
> On that note, what's the use of the tag argument? I have only seen
> hash_append_tag so far, and I don't think adding new tags in the future would
> be any different from using separate functions (i.e. to support a new tag
> would require about the same amount of user's code modifications as adding
> a new friend function to the user's classes).

This is the tag_invoke pattern:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1895r0.pdf

Instead of every library making up its own identifier for ADL purposes (e.g.
in Hash2 I used do_hash_append in the past), we use tag_invoke with a
library-specific tag.

The advantage is that the tag is namespaced.

If two libraries pick the same name for their ADL customization point, they
will conflict; but if two libraries pick the same tag name, they will not conflict
because the tags are in their respective namespaces.

We use tag_invoke in Boost.JSON as well.


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