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 7972863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:57:53+00:00 2026-06-04T07:57:53+00:00

I have a container object : R Container; R is of type list<T*> or

  • 0

I have a container object :

R Container;

R is of type list<T*> or vector<T*>

I am trying to write the following function:

template<typename T, typename R>
T& tContainer_t<T, R>::Find( T const item ) const
{   
typename R::const_iterator it = std::find_if(Container.begin(), Container.end(),  [item](const R&v) { return item == v; });
if (it != Container.end())
    return (**it);
else
    throw Exception("Item not found in container");
}

When trying the method (v is an object of my class)

double f = 1.1;
v.Find(f);

I get binary '==' : no operator found which takes a left-hand operand of type 'const double' (or there is no acceptable conversion)

I am confused with the lambda expression syntax and what i should write there and couldn’t find any friendly explanation.

What is wrong ? 10x.

  • 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-04T07:57:54+00:00Added an answer on June 4, 2026 at 7:57 am

    Missing a bit of context, but I note:

    • You return **it so you possibly want to compare *v==itemt
    • You pass const R&v where I suspect you meant const T&v into the lambda
    • You used a const_iterator, but returned a non-const reference. That was a mismatch
    • I made some params const& for efficiency (and to support non-copyable/non-movable types)

    Here is working code, stripped of the missing class references:

    #include <vector>
    #include <algorithm>
    #include <iostream>
    
    template<typename T, typename R=std::vector<T> >
    T& Find(R& Container, T const& item ) 
    {   
        typename R::iterator it = std::find_if(Container.begin(), Container.end(),  [&item](const T&v) { return item == v; });
        if (it != Container.end())
            return *it;
        else
            throw "TODO implement";
    }
    
    int main(int argc, const char *argv[])
    {
        std::vector<double> v { 0, 1, 2, 3 };
        Find(v, 2.0); // not '2', but '2.0' !
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method void foo(list<shared_ptr<Base>>& myList); Which I'm trying to call with a
I have a container class for urls and their headers, Resource: class Resource(object): def
I have a DLPUser object in my session, this DLPUser is basically a container
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have an object which is contained within a List<>, I need to remove
I have the following issue: A java object contains two arrays of core datastore
I have a list of radio button, not radiobuttonlist, I need to find out
I have these container objects (let's call them Container) in a list. Each of
I have two classes: Media and Container. I have two lists List<Media> and List<Container>
I have a container for nested objects like: class A { private Type type;//

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.