Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adaptive Function Object

42 views
Skip to first unread message

Doug Mika

unread,
May 26, 2015, 12:37:23 PM5/26/15
to
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? Or is it simply that there are two operator() functions in a class that is an adaptive function object?

Victor Bazarov

unread,
May 26, 2015, 1:04:23 PM5/26/15
to
Here it is:

http://lmgtfy.com/?q=%22adaptive+function+object%22+C%2B%2B

V
--
I do not respond to top-posted replies, please don't ask

Richard

unread,
May 26, 2015, 1:12:04 PM5/26/15
to
[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>

Doug Mika

unread,
May 27, 2015, 1:47:12 PM5/27/15
to
To Bazarov: I am very impressed with that little google presentation, first time I have seen it, HOWEVER, if you look at the search results, not one describes what exactly is an adaptive function (a mere definition would have suficed)!

So to Richard, a neat little function, but it has only one operator() function, not two, I guess that's not what makes a function object an adaptive function object? Then what exactly makes an adaptive function object ADAPTIVE?

Victor Bazarov

unread,
May 27, 2015, 1:52:08 PM5/27/15
to
I am guessing you need to learn terminology a bit, and it's outside of
the scope of this newsgroup to explain to you what "adaptive" or "an
adapter" means. Perhaps you should get a copy of the GoF book and read
about the Adapter pattern. Or you could just google for "Adapter
pattern"...

Richard

unread,
May 27, 2015, 5:56:39 PM5/27/15
to
[Please do not mail me a copy of your followup]

Doug Mika <doug...@gmail.com> spake the secret code
<b482173b-9e38-4fa2...@googlegroups.com> thusly:

>So to Richard, a neat little function, but it has only one operator()
>function, not two,

Why would it have two?

What I wrote was a functor that adapted a less-than comparison
function and a greater-than comparison function, defaulting to
std::less and std::greater, respectively. By your original post:

> By definition: A function object that combines two function objects is
> called an adaptive function object.

This is an example of exactly that.

As others have pointed out, if you don't understand what adapters are
in the context of functions, then you need to go learn that first.
0 new messages