PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 4, 2022

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

 November 04, 2022     c++, lambda, std     No comments   

Issue

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.



Answered By - Cat Plus Plus
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing