Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:38:48+00:00 2026-06-16T20:38:48+00:00

I have been fiddling around with lambda expressions to learn how they work but

  • 0

I have been fiddling around with lambda expressions to learn how they work but came across an issue. I have been trying to figure what I am doing wrong but can’t seem to. The compiler just refuses to accept this simple example:


  int a = 2;
  std::vector<int> vv(10);
  vv[2]=2;
  std::count( vv.begin(), vv.end(), [&a](int z) { return a == z; } );

I get the error


Error   1   error C2678: binary '==' : no operator found 
  which takes a left-hand operand of type 'int' (or there is no 
  acceptable conversion) e:\program files (x86)\microsoft visual studio
  11.0\vc\include\xutility 3243

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:38:49+00:00Added an answer on June 16, 2026 at 8:38 pm

    The algorithms need to know whether a predicate is based on comparing a value using equality or a unary predicate. To distinguish the two, a_if suffix is used for various algorithms: find_if(), `copy_if(), count_if(), etc. The lambda is OK but it isn’t equality-comparable to the value_type of the sequence. You need to use std::count_if() when using a predicate:

    std::count_if( vv.begin(), vv.end(), [&a](int z) { return a == z; } );
    

    … or a value:

    std::count( vv.begin(), vv.end(), a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been fiddling around with server side interceptors on CXF. But is seems
I have been fiddling around with Namespace in PHP and was trying to make
I have this, and i've been fiddling around with it for a while but
I have been fiddling with this issue all day now. I need to create
I've been fiddling around with arrays and array ordering recently and stumbled across something
I've been fiddling around with this for quite some time. I can't work out
I have been fiddling around with settings for a while, and cannot seem to
I have been fiddling with code to call a function with the name of
I Have been fiddling with this for hours. I can not get my text
Have been trying to encrypt an xml file to a string so that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.