Your goal is to write a function object Min_clamped that can be called as a function taking two arguments and returns the minimum between a member variable "_a" and the minimum of the two arguments. Min_clamped has one constructor:
// test_function_objects.cpp
#include <iostream>
template <class T>
class Min_clamped {
public:
Min_clamped (const T& a = 0) /* complete the code for the constructor */
// complete the class Min_clamped to have a function object
private:
T _a;
};
int main() {
Min_clamped<int> min_0;
std::cout << min_0(-1,-2) << std::endl;
std::cout << min_0(1,2) << std::endl;
Min_clamped<double> min_5(5.0);
std::cout << min_5(-1.5, -2.5) << std::endl;
std::cout << min_5(7.5, 7.0) << std::endl;
}
Your goal will be to write a template function my_find() taking as input an iterator pointing to the beginning of a container, an iterator pointing to the end of a container and an element 'e' and returning an iterator to the first found element in the container equal to 'e' or an iterator to the end of the container if no elements were found.
Please create a file "utils.h". Write your function template function my_find() in this file.
#include "utils.h"
#include <list>
#include <iostream>
int main()
{
std::list<int> l;
l.push_back(1); l.push_back(2);
l.push_back(5); l.push_back(1);
l.push_back(2);
std::list<int>::iterator it;
it = my_find(l.begin(), l.end(), 2);
if (it != l.end()) std::cout << "found " << *it << std::endl;
}
Write a program which reads integer numbers from std::cin using a std::istream_iterator. The program should print all even numbers, separated by spaces, to an output file. Use std::ostream_iterators for printing to the output file.