/***************************************************************************
 * This program illustrates the generic functions 'find' and 'find_if'.
 ***************************************************************************/
#include <iostream>
#include <list>
#include<vector>
#include<string>

using std::cin;           
using std::cout;            
using std::endl;            
using std::list;
using std::vector;
using std::string;

typedef vector<int> seq;// This could be replaced with a list.
void show_seq(const seq& s);
bool neg(int n)
{
	return n<0;
}


int main()
{

	seq custom;
	int x, query;
	string stop_string;
	cout<<"\nPlease enter space-separated integers, and 's' to stop:";
	while(cin>>x)
		custom.push_back(x);//Load 'custom' from the keyboard.
	cin.clear();
	cin>>stop_string;// Pull in the end character and discard.
	cout<<"The list 'custom' contains\n";
	show_seq(custom);
	//Prompt for a value to try to find.
	cout<<endl<<"Please enter the number to find: ";
	cin>>query;
	
	seq::iterator iter=find(custom.begin(), custom.end(), query);
	
	/*'find' returns an iterator indicating the first occurrence
	 * of the specified value, or the end() iterator if the value
	 * is not present.
	 */
	if(iter==custom.end())
		cout<<"\nThe query value is not in the sequence.";
	else
		cout<<*iter<<" was found in the sequence.";
	/* The third parameter for find_if is a function with the same 
	 * parameter type as indicated by the iterators and 'bool' as 
	 * its return type. 'find_if' returns an iterator to the first 
	 * position holding a value on which the function evaluates to
	 * 'true', or to the end() iterator if the function is false 
	 * for all values in the data.
	 */
	iter=find_if(custom.begin(), custom.end(), neg);
	if(iter==custom.end())
		cout<<"\nThere are no negative numbers in the sequence.";
	else
		cout<<"\nThe first negative number in the sequence is "
			<<*iter<<".";

	

	return 0;
	

	
}

void show_seq(const seq& s)
{
	for(seq::const_iterator iter=s.begin(); iter!=s.end();++iter)
		cout<<*iter<<" ";
	
	return;
}


