The sizeof... Operator

Image

When we need to know how many elements there are in a pack, we can use the sizeof... operator. Like sizeof4.9, p. 156), sizeof... returns a constant expression (§ 2.4.4, p. 65) and does not evaluate its argument:

template<typename ... Args> void g(Args ... args) {
    cout << sizeof...(Args) << endl;  // number of type parameters
    cout << sizeof...(args) << endl;  // number of function parameters
}


Exercises Section 16.4

Exercise 16.51: Determine what sizeof...(Args) and sizeof...(rest) return for each call to foo in this section.

Exercise 16.52: Write a program to check your answer to the previous question.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset