File: refbinding.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (28 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
A subtlety with using pointers to members in combination with 
reference bindings was observed by Mike
Spertus. Consider the following example in which a const member function
tt(fun) was declared with a reference token tt(&):
        verb(    struct Demo
    {
        void fun() const &;
    };)

Although tt(fun) was declared with a tt(&) reference token, it can
nevertheless be called from an anonymous (rvalue) tt(Demo) object, because
it's a const member function:
        verb(    Demo{}.fun();           // OK since C++20)

However, up to the C++20 standard this function could not be called
using a pointer-to-member construction from an anonymous tt(Demo)
object. This inconsistency was removed in the C++20 standard, allowing
the following statements to be correctly compiled:
        verb(    (Demo{}.*&Demo::fun)(); // using .* and fun's address

                            // pf receives fun's address
    void (Demo::*pf)() const & = &Demo::fun;

    (Demo{}.*pf)();         // call fun via the pointer pf)