/*Orion Lawlor's Simple STL Examples, olawlor@acm.org
Shows how to use std::find_if.
*/
#include <iostream>
#include <algorithm>
#include <cmath>

bool isPrime(double x) { //Extremely slow prime-checker
	double end=std::sqrt(x);
	if (x==1.0) return false;
	for (double divisor=2;divisor<=end;divisor+=1)
		if (0.0==std::fmod(x,divisor))
			return false;
	return true;
}

int main()
{
	double start[]={1,2,3,4,5,17,18,20,21,22,23,107,1007,10007};
	double *end=&start[sizeof(start)/sizeof(start[0])];
	
	double *i=start;
	while (1) {
		i=std::find_if(i,end,isPrime);
		if (i==end) break; //Special "not found" flag
		std::cout<<"Found prime "<<*i<<" at index "<<i-start<<std::endl;
		i++;
	}
	
	return 0;
}
/*<@>
<@> ******** Program output: ********
<@> Found prime 2 at index 1
<@> Found prime 3 at index 2
<@> Found prime 5 at index 4
<@> Found prime 17 at index 5
<@> Found prime 23 at index 10
<@> Found prime 107 at index 11
<@> Found prime 10007 at index 13
<@> */
