dimanche 19 avril 2020

Exact correspondence between r-value references and pointers?

This is a general question about symmetry between pointer and reference types in the C++ language.

Is this table of correspondence meaningful in C++ (C++11 and beyond)?

| Reference | Pointer  |
|-----------|----------|
| T&        | T*       |
| T const&  | T const* |
| T&&       | ???*     |

and if some, what would correspond to ???* ?. (Any additional rows are missing?)

My guess it will correspond to something like std::move_iterator<T*>, but it is not a built-in language and seems to create a bunch of other problems (like std::reference_wrapper does).

Is the language missing some kind of r-value pointer to be more symmetric? Or better said something that generates r-values on derreference (for example a moved object -- or a even a copy).

I know that r-value references correspond to thing that "do not have a name", however that doesn't seem to be constradictory if that samething is only obtained for a deference operation *.


NOTE 1:

I see std::move_iterator<It>::operator->() is deprecated in C++20. Which I am not sure what it means, perhaps it means that it can be implemented, optionally, sometimes. This question is relevant to this deprecation because in principle std::move_iterator<It>::operator->() could return ???* rather than pointer. (Or return move_iterator<pointer>, although that will generate a infinite regress of ->() operators... unless there is a true pointer for r-values.)


NOTE 2: A candidate missing row missing that I can imagine is:

| void& (not a thing)  | void*     |

but I think it is not related to the correspondence asked in the question, but a normal irregularity of void in the language.

Aucun commentaire:

Enregistrer un commentaire