2

I'm wondering about the execution order of function calls given in an initializer list:

#include <iostream>

class ExpandWithConstructor
{
    public:
        template < typename ... T>
            ExpandWithConstructor( T... args) {}
};

    template < typename T>
T Print( T t )
{
    std::cout << t << std::endl;
    return t;
}

int main()
{
    ExpandWithConstructor{ Print(1.1),Print("Hallo"),Print('c')};
}

Executing the code gives:

c
Hallo
1.1

Q: Is the reverse order of functions defined in the standard or is there no guarantee for the ordering?

I use g++ 4.8.1.

Klaus
  • 24,205
  • 7
  • 58
  • 113
  • 1
    Related: http://stackoverflow.com/questions/14060264/order-of-evaluation-of-elements-in-list-initialization and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253 – hmjd Aug 19 '13 at 14:37
  • Thanks! Yes, your link exactly answer what I ask for! – Klaus Aug 19 '13 at 14:44
  • TLDR: Yes it's defined, no it's not reverse order, [GCC has a bug](http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253). – Casey Aug 19 '13 at 14:48

0 Answers0