File: refbinding.yo

package info (click to toggle)
c%2B%2B-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (25 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
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
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++2a)

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

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

    (Demo{}.*pf)();         // call fun via the pointer pf (OK since C++2a))