[Please do not mail me a copy of your followup]
Doug Mika <
doug...@gmail.com> spake the secret code
<
e8c0d08b-16da-47c2...@googlegroups.com> thusly:
>By definition: A function object that combines two function objects is
>called an adaptive function object. Can anyone provide me with an
>example of an adaptive function object or a link to an example?
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>
template <
typename T,
typename Less = std::less<T>,
typename More = std::greater<T>
>
class range_comparison
{
public:
range_comparison(T min_bound, T max_bound)
: m_min_bound(min_bound),
m_max_bound(max_bound)
{
}
bool operator()(T val)
{
return !lesser(val, m_min_bound) && !greater(val, m_max_bound);
}
private:
Less lesser;
More greater;
T m_min_bound;
T m_max_bound;
};
int main()
{
std::vector<int> vals{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::copy_if(std::begin(vals), std::end(vals),
std::ostream_iterator<int>(std::cout, "\n"),
range_comparison<int>(3, 6));
}
gives
3
4
5
6
--
"The Direct3D Graphics Pipeline" free book <
http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <
http://computergraphicsmuseum.org>
The Terminals Wiki <
http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <
http://legalizeadulthood.wordpress.com>