Search code examples
c++stdlambda

Why std::generate will work with lambda generator and std::fill will not?


I have stumbled across this website : http://www2.research.att.com/~bs/C++0xFAQ.html#lambda where they explain lambda functions. I have tried to use the provided examples, namely :

    vector<int> indices( notImportantNumber );
    int count = 0;
    fill(indices.begin(), indices.end(), [&](){ return ++count; });

and similarly

    generate(indices.begin(), indices.end(), [&](){ return ++count; });

Although, when I try to use the example with fill I keep on getting this error :

Error 1 error C2440: '=' : cannot convert from 'const `anonymous-namespace'::' to 'long' c:\program files\microsoft visual studio 10.0\vc\include\xutility 2692

Anyone knows why is this happening ? In the declarations of std::fill() there is no functor as the last parameter.


Solution

  • It's an error on that website. std::fill takes a value to fill with, not a callable.