I've seen cases before where it was intended to write a variable declaration
but a function prototype was written instead (e.g. X x();) but I've come
accross a new version of this (new to me at least) and I want to check I've
understood it correctly.
The code I wrote was.
std::istringstr eam buf("abc");
std::vector<cha r> vec(std::istrea m_iterator<char >(buf),
std::istream_it erator<char>()) ;
To my surprise vec was interpreted as a function prototype. After a bit of
thought here's how I see it
std::istream_it erator<char>(bu f)
is a parameter declaration with std::istream_it erator<char> as the type and
buf as the dummy parameter name, and also a superfluous pair of parens. So
far so good, the bit that I couldn't work out was how
std::istream_it erator<char>()
was being interpreted as a parameter declaration. Then it occured to me that
in function declarations you are allowed to omit the dummy parameter name,
so that std::istream_it erator<char>() could be interpreted as parameter
declaration with superfluous parens surrounding the missing dummy parameter
name!
Is this a correct interpretation? Or am I barking?
john
but a function prototype was written instead (e.g. X x();) but I've come
accross a new version of this (new to me at least) and I want to check I've
understood it correctly.
The code I wrote was.
std::istringstr eam buf("abc");
std::vector<cha r> vec(std::istrea m_iterator<char >(buf),
std::istream_it erator<char>()) ;
To my surprise vec was interpreted as a function prototype. After a bit of
thought here's how I see it
std::istream_it erator<char>(bu f)
is a parameter declaration with std::istream_it erator<char> as the type and
buf as the dummy parameter name, and also a superfluous pair of parens. So
far so good, the bit that I couldn't work out was how
std::istream_it erator<char>()
was being interpreted as a parameter declaration. Then it occured to me that
in function declarations you are allowed to omit the dummy parameter name,
so that std::istream_it erator<char>() could be interpreted as parameter
declaration with superfluous parens surrounding the missing dummy parameter
name!
Is this a correct interpretation? Or am I barking?
john
Comment