C++ Logo

std-proposals

Advanced search

[std-proposals] Unary dereference/addressof as function objects

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 24 Aug 2023 20:56:04 +0200
Hi,

Has anyone ever proposed or thought of proposing to add the unary *
operator (and possibly unary &) as function objects in <functional>? I
find myself using * quite often (in algorithms, range pipelines, ...),
it would be nice to have it as a standard function object; the
implementation is trivial.

As of operator&, I don't think I've ever had the need for it, but I
guess it should be proposed together for symmetry.

Happy to write a paper if no-one has beaten me to it.


---
Since I foresee an inevitable bikeshedding on the naming: does anyone 
possibly know where the currently existing function objects got their 
names from? Why is std::divides a verb in the third-person singular 
form, but std::negate is not? Why are those verbs, and e.g. std::plus is 
a noun instead?
Some possible ideas:
1) std::indirection
The name of the operator in the language. If we go down this route, then 
the function object for operator& ought to be called std::addressof, 
which is a) already taken and b) a false friend! (Does NOT call an 
overloaded operator& by design; it's not a function object; and doesn't 
live in <functional> but in <memory>!)
2) std::star
How the symbol is usually referred to in CS -- typographically, it's an 
asterisk (U+002A ASTERISK). But this clashes with the binary *, which is 
spelled std::multiplies (i.e. the name of the logical operation, and 
nothing to do with the symbol).
3) std::asterisk
Ditto.
4) std::dereference (std::dereferences?)
This is the logical operation, and my preferred choice. But does this 
mean that operator& should be spelled, for symmetry, std::reference(s)? Eww.
Thanks,
-- 
Giuseppe D'Angelo

Received on 2023-08-24 18:56:08