Sign in to follow this  
a1234b

[C++] overloading std::find_if

Recommended Posts

I thought I was doing everything right, as I even copy-pasted the solutions from GD and modified them to my liking. Now it's still not working and I'm giving out my code for some fresh eyes to see.
#include <fstream>
#include <iostream>
#include <string>

#include <exception>
#include <algorithm>
#include <vector>

using namespace std;

	// Harspoolov algoritem
    struct bch_element_t {
    
        bch_element_t( const char c ) 
        : znak( c ), odmik( int() ) {}    
        
		bool operator()( const bch_element_t &rhs )
        {
            return this->znak == rhs.znak;
        }
        
        char znak;
        int odmik; 
    };

        
int main()
{
        // declaration
        string c[3] = { "bla1", "bla2", "bla3" };
	vector<bch_element_t> bch[3];
	 
        // i've push_back'd some elements..

        // and then did this (is this the correct usage?)
	if( find_if( bch[i].begin(), bch[i].end(), bch_element_t( c[i][j] ) ) == false )

}


but the compiler gives out this error: 76 H:\ARP\dn_n_fix.cpp no match for ` __gnu_cxx::__normal_iterator<bch_element_t*, std::vector<bch_element_t, 65 C:\Program Files\Dev-Cpp\include\objbase.h candidates are: BOOL operator==(const GUID&, const GUID&) thanks! PS: I'd also like to note, that I've first tried overloading std::find (as it doesn't matter which one I use), and the same error occured.

Share this post


Link to post
Share on other sites
find_if does not return a boolean (so you get an error on the '== false' comparison). It returns an iterator within the range that satisfies the predicate (if any) or the past-the-end iterator for the range (if none). So, your comparison would be '== bch[i].end()' instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this