-2

I want to do this:

std::istringstream foo( "13 14 15 16 17 18 19 20" );
std::vector<int> bar( std::istream_iterator<int>( bytes ), std::istream_iterator<int>() );

But rather than recognizing it as the vector range ctor, the compiler thinks that I'm prototyping a function.

Is there a way that I can hint to the compiler what's going on?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288

1 Answers1

1

If your compiler supports C++11 and uniform initialization you may do

std::vector<int> bar{ std::istream_iterator<int>( bytes ), std::istream_iterator<int>() };

If not, then change to

std::vector bar = std::vector<int>( std::istream_iterator<int>( bytes ), std::istream_iterator<int>() );

Read more about variable initialization vs function declaration ambiguity on Sutter's Mill.

Paul
  • 13,042
  • 3
  • 41
  • 59