for and bool function problem

closed account (EwCjE3v7)
I havn't touched code for a while now and dont know why "Success! (num)" dont print. Shouldn't "Success! 6 print?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
bool check_size(const string &s, string::size_type sz)
{
	return s.size() >= sz;
}

int main()
{
	string s = "Hello";
	vector<int> nums = {1, 3, 5, 6, 1};

	auto vecHasGreater = bind(check_size, s, _1);

	for (auto beg = nums.begin(); !vecHasGreater(*beg); ++beg) {
		cout << "Success! " << *beg << endl;
	}

	return -1;
}
Do not forget that if at any point condition is false, loop stops executing.
your first element returns true from check_size function which is negated and so loop stops immideatly
closed account (EwCjE3v7)
Oh that is what I forgot, thank you. Can`t believe I forgot that :/. Thank you :)
Topic archived. No new replies allowed.