C++11 universal reference pop-quiz
Here’s a little exercise for anyone who, like me, recently came across
Scott Meyers’ work on universal references in C++11: Is
the following program well formed? Does it have well-defined behaviour? If not,
why not? If so, what is the value returned by main()
? Why? References,
please!
I have written the program so that it needs no #include
directives, and
therefore you can be sure there is not a single typedef
, decltype
or auto
specifier anywhere in or out of sight. That means there’s only one way that
so-called universal references can arise.
However, you might find one or two other little surprises. Oh, and Clang 3.3 and GCC 4.8.1 don’t even agree on this program, so there’s not much point in cheating!