I have some function to find a value:
struct FindPredicate
{
FindPredicate(const SomeType& t) : _t(t) {
}
bool operator()(SomeType& t) {
return t == _t;
}
private:
const SomeType& _t;
};
bool ContainsValue(std::vector<SomeType>& v, SomeType& valueToFind) {
return find_if(v.begin(), v.end(), FindPredicate...
Hi,
I found the following code in the book "Accelerated C++" (Chapter 6.1.1), but I can't compile it. The problem is with the find_if lines. I have the necessary includes (vector, string, algorithm, cctype). Any idea?
Thanks, Jabba
bool space(char c) {
return isspace(c);
}
bool not_space(char c) {
return !isspace(c);
}
vector<s...
Is there an alternative version of std::find_if that returns an iterator over all found elements, instead of just the first one?
Example:
bool IsOdd (int i) {
return ((i % 2) == 1);
}
std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
std::vector<int>::iterator it = find_if(v.begin(), v.end(), IsOd...
Hello! I have to work with an application in C++ similar to a phone book: the class Agenda with an STL list of Contacts.Regarding the contacts hierarchy,there is a base-class named Contact(an abstract one),and the derived classes Friend and Acquaintance(the types of contact).
These classes have,for instance, a virtual method called...
Hi,
I'm using the STL function count_if to count all the positive values
in a vector of doubles. For example my code is something like:
vector<double> Array(1,1.0)
Array.push_back(-1.0);
Array.push_back(1.0);
cout << count_if(Array.begin(), Array.end(), isPositive);
where the function isPositive is defined as
bool isPosit...
I would like to use Boost Phoenix to generate a lambda function for use in a std::find_if operation on a structure that contains reference-type members. A contrived example is as follows:
struct MyStruct
{
MyStruct() : x(0) {}
int& x;
};
std::vector<MyStruct> AllStructs;
// Search the array for an element for which x == 5...
Hi,
I'm tring to calculate the standard deviation of a vector of doubles (called A).
Now I have a function called StDev that will do this. However, the first
few elements of vector A are zero and I need to remove these. To do this I
create a sub-array and then pass this to my StDev function as follows:
std::vector<double> Array(f...
my code works perfectly in visual studio yet i encounter a problem running it in eclipse.
in the function:
City* Gps::FindCity(const char* city)
{
if(city != NULL)
{
City *tmp = NULL;
if (! m_gpsCities.empty())
{
for (list<City*>::iterator iter = m_gpsCities.begin(); iter != m_gpsCities.end();...
I know that I can check whether a list of lists only contains null lists like this
CL-USER> (null (find-if (lambda (item) (not (null item))) my-list))
where my-list is a list of lists.
For example:
CL-USER> (null (find-if (lambda (item) (not (null item))) '(nil (bob) nil)))
NIL
CL-USER> (null (find-if (lambda (item) (not (null item)...