C++ Templated Delegates like Unity - c++

after saw Unity's delegates and events, i'm trying to code my own:
I want to create a class with a variadic template, to specify the return type of the functions, and optionals arguments.
template <typename Ret, typename... Args>
class MyDelegate{
std::vector<Ret(*)(Args...)> vec;
public:
void operator+=( const Ret(*)(Args...)& newElement)
{
vec.push_back(newElement);
}
Ret operator()(const Args&... args)
{
for (auto i = vec.begin(); i != vec.end(); ++i)
(*i)(args...);
}
};
As you can see, i would like this class to be used this way:
MyDelegate<void> voidDelegate;
MyDelegate<void, int> intDelegate;
MyDelegate<int, char, boolt> miscDelegate;
and "adding" functions to each one using += operators, like:
voidDelegate += voidFunc;
//etc...
I'm having problem with the += operator for now, because VS don't accept this:
MyDelegate<void, int> delegate1;
delegate1 += [](const int a)->void{std::cout << a << std::endl; };
The lambda function is correct: it take an int and return void, so i don't understand whats' wrong.

The issue is that your std::vector stores function pointers. It doesn't store std::bind objects, it doesn't store member functions, it doesn't store functors and it doesn't store lambdas. You are trying to add a lambda to it, hence the failure.
If you want to store any kind of object which supports calling with the correct argument and return types, you want std::function:
using FunType = std::function<Ret(Args...)>;
std::vector<FunType> vec;
Demo
Incidentally, you could improve your solution by perfect-forwarding your operator() args and copying your newElement arg in the interface and moving it into the std::vector.

Your delegate accepts only function pointers. A lambda is not a function pointer. However, the lambda that you are trying to doesn't capture anything. Which means that it can be converted to a function pointer thanks to some sorcery:
MyDelegate<void, int> delegate1;
delegate1 += +[](const int a)->void{std::cout << a << std::endl; };
↑↑↑
However, once you want to allow functors that have member variables, the extra + won't work:
delegate1 += +[x](const int a) { ... }; // error: no match for operator+
At which point you'll definitely have to use TartanLlama's suggestions of std::function.

#TartanLlama's right, std::function is what you need.
And the calling loop can be folded to for (auto handler : vec) handler(args...);

Related

How to properly store lambda functions in a tuple and call them?

I'm trying to create a class that can store functions in a member tuple. But when trying to put lambdas inside of an object's tuple (through function pointers) I'm getting a error. Please explain, what I'm doing wrong and what is the proper way of releasing this idea. I think there should be an elegant and stylistically correct general solution (in terms of functional programming patterns) to avoid boilerplate code in class description, objects creation and filling them with functions.
#include <functional>
#include <string>
#include <iostream>
template<typename... ArgTypes>
class MyClass {
public:
//boolean function of some argument
template<typename Type> using Func = bool(Type const &);
//type for a tuple of pointers to templated boolean functions
template<typename... Types> using TupleOfFunctions = typename std::tuple<Func<Types>*...>;
//the tuple
TupleOfFunctions<ArgTypes...> _tuple;
//constructor
MyClass(TupleOfFunctions<ArgTypes...> t) : _tuple(t) {
}
};
int main(int argc, char** argv) {
MyClass<int, std::string> M({
[](int &arg) { return arg > 0; },
[](std::string &arg) { return arg == "abc"; }
});
std::cout << (*std::get<0>(M._tuple))(1);
std::cout << (*std::get<1>(M._tuple))("xyz");
return 0;
}
The error I get is
./test.cpp:26:3: error: no matching function for call to 'MyClass<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::MyClass(<brace-enclosed initializer list>)'
26 | });
template<typename Type> using Func = bool(Type const &);
This line suggested functions taking in const type arguments. However:
[](int &arg) { return arg > 0; },
[](std::string &arg) { return arg == "abc"; }
These two lines suggested non-const arguments.
Either remove the const from the first line, or add const to the second two should solve it.
Could you, however, suggest some ideas of redesigning the class so that the boilerplate code of repeated explicit declaration of these types (in class template specification and lambda function arguments) can be avoided?
Part of the point of having lambda is anonymous function type. Actually trying to deduce a type of them, like what you did, was kind of going backward.
One way I would suggest to do this would be:
template<typename ... Lambdas>
class MyClass {
public:
std::tuple<Lambdas...> _tuple;
MyClass(Lambdas ... args) : _tuple(std::make_tuple(args ...)) {
}
};
Now you can use it like:
MyClass M(
[](const int &arg) { return arg > 0; },
[](const std::string &arg) { return arg == "abc"; }
);
Alternatively, you might be interested in a variant/visit pattern: https://godbolt.org/z/5Pdn1Ynqe
A braced-init-list, like {}, does not actually have a type. In the context of template deduction, you can only use them in certain cases - when deducing against initializer_list (where T is a function template parameter) or when the corresponding parameter is already deduced by something else. In this case, neither of those two things is true - so the compiler cannot figure out what ...ArgTypes is supposed to be.
I think you should use std::make_tuple and store as lambda as function pointer.
Live example

Pass a member function as Compare operator for C++ standard library algorithm

In my code I have now something like
Foo bar;
std::unordered_set<Foo>::iterator minElement =
std::min_element(std::begin(mySet),
std::end(mySet),
[&bar](Foo const &lhs, Foo const &rhs) {
return bar.myWeakLessOperator(lhs, rhs);
});
I wonder wether it exists a way to simplify it by passing directly the member function myWeakLessOperator (that is not static) instead of writing a lambda function just to make to call.
I would like to obtain something like
Foo bar;
std::unordered_set<Foo>::iterator minElement =
std::min_element(std::begin(mySet),
std::end(mySet),
/* something that rely to */ bar.myWeakLessOperator);
Any idea if it possible and how to do it ?
A possible solution is to use a struct that satisfies Compare inside Foo:
class Foo
{
public:
struct WeakLessOperator
{
bool operator()(const Foo& a, const Foo& b)
{
// implementation - take care of meeting requirements of Compare
return true;
}
};
WeakLessOperator myWeakLessOperator;
};
Foo bar;
auto minElement =
std::min_element(std::begin(mySet),
std::end(mySet),
bar.myWeakLessOperator);
So you want to have a function object that represents a member function bound to a particular receiver. Unfortunately, there's nothing I could find in the standard or Boost that does that.
What you can do is write your own fairly easily.
template <typename R, typename T>
struct member_function_binder {
T *receiver;
R T::*pmf;
template <typename... Args>
auto operator()(Args&&... args) {
return (receiver->*pmf)(std::forward<Args>(args)...);
}
};
template <typename R, typename T>
auto bind_member_function(R T::*pmf, T &receiver) {
return member_function_binder<R, T>{&receiver, pmf};
}
Have a look at the live demo, I think this might be what you want.
Even more concise, you don't need to have a separate class member_function_binder if you return a lambda from bind_member_function like so:
template <typename R, typename T>
auto bind_member_function(R T::*pmf, T &receiver) {
return [pmf, &receiver](auto&&... args) {
return (receiver.*pmf)(std::forward<decltype(args)>(args)...);
};
}
Live demo
Solution to pass a unary member function like Foo::compareTo(const Foo &rhs), not what OP asked:
What you want is std::mem_fn; it's a wrapper that makes a member function pointer into a function object. You would use it like this:
auto min = std::min_element(
begin(mySet), end(mySet), std::mem_fn(&Foo::myWeakLessOperator));
you can use std::bind, or some other wrapper.
EXAMPLE:
using namespace std::placeholders;
Foo bar;
std::unordered_set<Foo>::iterator minElement =
std::min_element(std::begin(mySet),
std::end(mySet),
std::bind(&Foo::myWeakLessOperator, bar, _1, _2));
OR
Foo bar;
std::unordered_set<Foo>::iterator minElement =
std::min_element(std::begin(mySet),
std::end(mySet),
gnr::memfun<MEMFUN(Foo::myWeakLessOperator)>(bar));
The closest to what you want is maybe
auto minElement =
std::min_element(
std::begin(mySet),
std::end(mySet),
mem_fun_functor(&Foo::myWeakLessOperator)
);
There is std::mem_fun (deprecated in c++11) and std::mem_fn both wrap a member function pointer, though both take a instance as parameter to invoke the member function. If you want a functor that wraps the object also, i think you need to write your own:
auto mem_fun_functor =
[&bar](decltype(&Foo::myWeakLessOperator) f){
return [f,&bar](const Foo& a,const Foo& b) {
return (bar.*f)(a,b);
};
};
However, given that none of the answers is really much shorter or leading to cleaner code, I would consider to just use your first version with the lambda (unless you maybe have many different member functions that you want to use as comparator).
What do you actually mean by "simplifying" ? You do need to specify the object you want to call the member function on, you need to specify how you want to forward the parameters. Thats basically all the lambda does.
Defering all this to a functor as for example above makes your code more complicated rather than simpler. In your first snippet anybody familiar with standard algorithms can look at that few lines of code and fully understand what is going on.
Eventually it is a matter of style, and what you consider as readable, but being able to declare stuff in the most narrowest scope is one big advantage of using lambdas.

Containers for different signature functions

I'm trying to programming in C++ a framework where the user can indicates a set of functions inside its program where he wants to apply a memoization strategy.
So let's suppose that we have 5 functions in our program f1...f5 and we want to avoid the (expensive) re-computation for the functions f1 and f3 if we already called them with the same input. Notice that each function can have different return and argument types.
I found this solution for the problem, but you can use only double and int.
MY SOLUTION
Ok I wrote this solution for my problem, but I don't know if it's efficient, typesafe or can be written in any more elegant way.
template <typename ReturnType, typename... Args>
function<ReturnType(Args...)> memoize(function<ReturnType(Args...)> func)
{
return ([=](Args... args) mutable {
static map<tuple<Args...>, ReturnType> cache;
tuple<Args...> t(args...);
auto result = cache.insert(make_pair(t, ReturnType{}));
if (result.second) {
// insertion succeeded so the value wasn't cached already
result.first->second = func(args...);
}
return result.first->second;
});
}
struct MultiMemoizator
{
map<string, boost::any> multiCache;
template <typename ReturnType, typename... Args>
void addFunction(string name, function < ReturnType(Args...)> func) {
function < ReturnType(Args...)> cachedFunc = memoize(func);
boost::any anyCachedFunc = cachedFunc;
auto result = multiCache.insert(pair<string, boost::any>(name,anyCachedFunc));
if (!result.second)
cout << "ERROR: key " + name + " was already inserted" << endl;
}
template <typename ReturnType, typename... Args>
ReturnType callFunction(string name, Args... args) {
auto it = multiCache.find(name);
if (it == multiCache.end())
throw KeyNotFound(name);
boost::any anyCachedFunc = it->second;
function < ReturnType(Args...)> cachedFunc = boost::any_cast<function<ReturnType(Args...)>> (anyCachedFunc);
return cachedFunc(args...);
}
};
And this is a possible main:
int main()
{
function<int(int)> intFun = [](int i) {return ++i; };
function<string(string)> stringFun = [](string s) {
return "Hello "+s;
};
MultiMemoizator mem;
mem.addFunction("intFun",intFun);
mem.addFunction("stringFun", stringFun);
try
{
cout << mem.callFunction<int, int>("intFun", 1)<<endl;//print 2
cout << mem.callFunction<string, string>("stringFun", " World!") << endl;//print Hello World!
cout << mem.callFunction<string, string>("TrumpIsADickHead", " World!") << endl;//KeyNotFound thrown
}
catch (boost::bad_any_cast e)
{
cout << "Bad function calling: "<<e.what()<<endl;
return 1;
}
catch (KeyNotFound e)
{
cout << e.what()<<endl;
return 1;
}
}
How about something like this:
template <typename result_t, typename... args_t>
class Memoizer
{
public:
typedef result_t (*function_t)(args_t...);
Memoizer(function_t func) : m_func(func) {}
result_t operator() (args_t... args)
{
auto args_tuple = make_tuple(args...);
auto it = m_results.find(args_tuple);
if (it != m_results.end())
return it->second;
result_t result = m_func(args...);
m_results.insert(make_pair(args_tuple, result));
return result;
}
protected:
function_t m_func;
map<tuple<args_t...>, result_t> m_results;
};
Usage is like this:
// could create make_memoizer like make_tuple to eliminate the template arguments
Memoizer<double, double> memo(fabs);
cout << memo(-123.456);
cout << memo(-123.456); // not recomputed
It's pretty hard to guess at how you're planning to use the functions, with or without memoisation, but for the container-of-various-function<>s aspect you just need a common base class:
#include <iostream>
#include <vector>
#include <functional>
struct Any_Function
{
virtual ~Any_Function() {}
};
template <typename Ret, typename... Args>
struct Function : Any_Function, std::function<Ret(Args...)>
{
template <typename T>
Function(T& f)
: std::function<Ret(Args...)>(f)
{ }
};
int main()
{
std::vector<Any_Function*> fun_vect;
auto* p = new Function<int, double, double, int> { [](double i, double j, int z) {
return int(i + j + z);
} };
fun_vect.push_back(p);
}
The problem with this is how to make it type-safe. Look at this code:
MultiMemoizator mm;
std::string name = "identity";
mm.addFunction(name, identity);
auto result = mm.callFunction(name, 1);
Is the last line correct? Does callFunction have the right number of parameters with the right types? And what is the return type?
The compiler has no way to know that: it has no way of understanding that name is "identity" and even if it did, no way to associate that with the type of the function. And this is not specific to C++, any statically-typed language is going to have the same problem.
One solution (which is basically the one given in Tony D's answer) is to tell the compiler the function signature when you call the function. And if you say it wrong, a runtime error occurs. That could look something like this (you only need to explicitly specify the return type, since the number and type of parameters is inferred):
auto result = mm.callFunction<int>(name, 1);
But this is inelegant and error-prone.
Depending on your exact requirements, what might work better is to use "smart" keys, instead of strings: the key has the function signature embedded in its type, so you don't have to worry about specifying it correctly. That could look something like:
Key<int(int)> identityKey;
mm.addFunction(identityKey, identity);
auto result = mm.callFunction(identityKey, 1);
This way, the types are checked at compile time (both for addFunction and callFunction), which should give you exactly what you want.
I haven't actually implemented this in C++, but I don't see any reason why it should be hard or impossible. Especially since doing something very similar in C# is simple.
you can use vector of functions with signature like void someFunction(void *r, ...) where r is a pointer to result and ... is variadic argument list. Warning: unpacking argument list is really inconvenient and looks more like a hack.
At first glance, how about defining a type that has template arguments that differ for each function, i.e.:
template <class RetType, class ArgType>
class AbstractFunction {
//etc.
}
have the AbstractFunction take a function pointer to the functions f1-f5 with template specializations different for each function. You can then have a generic run_memoized() function, either as a member function of AbstractFunction or a templated function that takes an AbstractFunction as an argument and maintains a memo as it runs it.
The hardest part will be if the functions f1-f5 have more than one argument, in which case you'll need to do some funky things with arglists as template parameters but I think C++14 has some features that might make this possible. An alternative is to rewrite f1-f5 so that they all take a single struct as an argument rather than multiple arguments.
EDIT: Having seen your problem 1, the problem you're running into is that you want to have a data structure whose values are memoized functions, each of which could have different arguments.
I, personally, would solve this just by making the data structure use void* to represent the individual memoized functions, and then in the callFunction() method use an unsafe type cast from void* to the templated MemoizedFunction type you need (you may need to allocate MemoizedFunctions with the "new" operator so that you can convert them to and from void*s.)
If the lack of type safety here irks you, good for you, in that case it may be a reasonable option just to make hand-written helper methods for each of f1-f5 and have callFunction() dispatch one of those functions based on the input string. This will let you use compile-time type checking.
EDIT #2: If you are going to use this approach, you need to change the API for callFunction() slightly so that callFunction has template args matching the return and argument types of the function, for example:
int result = callFunction<int, arglist(double, float)>("double_and_float_to_int", 3.5, 4);
and if the user of this API ever types the argument type or return types incorrectly when using callFunction... pray for their soul because things will explode in very ugly ways.
EDIT #3: You can to some extent do the type checking you need at runtime using std::type_info and storing the typeid() of the argument type and return type in your MemoizedFunction so that you can check whether the template arguments in callFunction() are correct before calling - so you can prevent the explosion above. But this will add a bit of overhead every time you call the function (you could wrap this in a IF_DEBUG_MODE macro to only add this overhead during testing and not in production.)

Data type calling template method

How do I use different data types without the overhead of writing a line of code for each type?
Say if there's a template method that takes any data type.
And I want to pass in various data types (int, double, string, char, ...etc) without creating a line for each data type.
Is there an efficient way of looping through different data types and call the template method for each data type??
Sample Code:
template <typename T>
sorted_vector<T>::sorted_vector( sorted_vector<value_type> const& rhs )
: beg_( new value_type [rhs.size()] )
, end_( beg_ + rhs.size() )
, cap_( end_ )
{
std::copy( rhs.beg_, rhs.end_, beg_ );
}
So my task is to test the template with bugs but wanted to check all value_types.
And I wanted to test a vector, vector, vector, etc etc
You may loop using variadic template:
class Test
{
public:
template <typename T>
static void f()
{
// Your generic code to execute
std::cout << typeid(T).name() << std::endl;
}
};
template<typename F, typename ... Ts>
void Call()
{
std::initializer_list<int>({ (F::template f<Ts>(), 0)... });
}
And then call it that way:
Call<Test, int, char, char*>();
But I'm not sure it is more clear than
// Equivalent to
Test::f<int>();
Test::f<char>();
Test::f<char*>();
It is difficult to understand what you are really asking as your question is too broad. I would recommend to look into boost::variant and especially how pattern 'visitor' is implemented there. It does not mean you have to use exactly this library, but this could be a good start point how to implement such logic. Other candidates would be std::tuple and boost::any
Sound like a case for Template Metaprogramming.
Look at the foreach of Boost's MPL: foreach
Their example does something like you try to do: Calling a functor for different types and values of a list.
struct value_printer
{
template< typename U > void operator()(U x)
{
std::cout << x << 'n';
}
};
int main()
{
for_each< range_c<int,0,10> >( value_printer() );
}

Syntactic sugar: automatically creating simple function objects

I am to implement a set of class templates and two special variables, _1 and _2.
They should make the following a legal code:
// Sort ascending
std::sort(a, a+5, _1 > _2);
// Output to a stream
std::for_each(a, a+5, std::cout << _1 << " ");
// Assign 100 to each element
std::for_each(a, a+5, _1 = 100);
// Print elements increased by five 5
std::transform(a, a+5, std::ostream_iterator<int>(std::cout, " "), _1 + 5);
I suppose that _1 * 5 should also yield an unary function, as well as _1 / 5 etc.
No boost allowed
No lambdas allowed
Now I have very little experience with templates and template metaprogramming, so I don't even know where to start and what the structure of my class templates should look like. I am especially confused as I don't know if inside my class templates I will have to write implementations for all these operator=, operator>>, operator+, ...-, ...*, .../ separately - or there is a more generic way to do it.
I will be particularly grateful to an answer with an example of implementation of these operators; templates still seem like a great mess to me.
Well! That is a tricky homework problem, indeed! But, it's also a very good problem to work on and to learn from.
I think that the best way to answer this is for you to start off with simple use cases and incrementally build up your solution.
For example, suppose that you have the following std::vector<int> to work with:
std::vector<int> vec;
vec.push_back(4);
vec.push_back(-8);
vec.push_back(1);
vec.push_back(0);
vec.push_back(7);
You'll obviously want to allow the following use case:
std::for_each(vec.cbegin(), vec.cend(), _1);
But how to allow this? First you'll need to define _1 and then you'll need to implement an "anything goes" overload of the function call operator for the type of _1.
The way that Boost Lambda and Boost Bind define placeholders objects _1, _2, ... is to make them have a dummy type. For example, the _1 object might have the type placeholder1_t:
struct placeholder1_t { };
placeholder1_t _1;
struct placeholder2_t { };
placeholder2_t _2;
Such a "dummy type" is frequently, informally called a tag type. There are many C++ libraries and indeed the STL that rely on tag types (e.g. std::nothrow_t). They are used to pick the "right" function overload to execute. Essentially, dummy objects are created having a tag type and these are passed into a function. The function does not use the dummy object in any way (in fact, most of the time a parameter name is not even specified for it), but by the existence of that extra parameter, the compiler is able to pick the correct overload to call.
Let's extend the definition of placeholder1_t by adding overloads of the function call operator. Remember that we want it to accept anything, so the overloads of the function call operator will themselves be templated on the argument type:
struct placeholder1_t
{
template <typename ArgT>
ArgT& operator()(ArgT& arg) const {
return arg;
}
template <typename ArgT>
const ArgT& operator()(const ArgT& arg) const {
return arg;
}
};
That's it! Our simplest of use cases will now compile and run:
std::for_each(vec.cbegin(), vec.cend(), _1);
Of course, it basically amounts to a no-op.
Let's now work on _1 + 5. What should that expression do? It should return a unary functional object that, when invoked with an argument (of some unknown type), the result is that argument plus 5. Making this more generic, the expression is unary-functional-object + object. The returned object is itself a unary functional object.
The type of the returned object needs to be defined. It will be a template with two template type parameters: the unary functional type and the type of the object that is being added to the result of the unary functional:
template <typename UnaryFnT, typename ObjT>
struct unary_plus_object_partfn_t;
"partfn" refers to a functional type representing partial application of the binary + operator. Instances of this type need a copy of the unary functional object (having type UnaryFnT) and the other object (having type ObjT):
template <typename UnaryFnT, typename ObjT>
struct unary_plus_object_partfn_t
{
UnaryFnT m_fn;
ObjT m_obj;
unary_plus_object_partfn_t(UnaryFnT fn, ObjT obj)
: m_fn(fn), m_obj(obj)
{
}
};
Okay. The function call operator also needs to be overloaded to allow for any argument. We'll use the C++11 decltype feature to refer to the type of an expression as we don't know what it is beforehand:
template <typename UnaryFnT, typename ObjT>
struct unary_plus_object_partfn_t
{
UnaryFnT m_fn;
ObjT m_obj;
unary_plus_object_partfn_t(UnaryFnT fn, ObjT obj)
: m_fn(fn), m_obj(obj)
{
}
template <typename ArgT>
auto operator()(ArgT& arg) const -> decltype(m_fn(arg) + m_obj) {
return m_fn(arg) + m_obj;
}
template <typename ArgT>
auto operator()(const ArgT& arg) const -> decltype(m_fn(arg) + m_obj) {
return m_fn(arg) + m_obj;
}
};
It's starting to get complicated, but there are no surprises in this code. It essentially says that the function call operator is overloaded to accept practically any argument. It will then call m_fn (the unary functional object) on the argument and add m_obj to the result. The return type is the decltype of m_fn(arg) + m_obj.
Now that the type is defined, we can write the overload of binary operator + accepting an object of type placeholder1_t on the left:
template <typename ObjT>
inline unary_plus_object_partfn_t<placeholder1_t, ObjT> operator+(const placeholder1_t& fn, ObjT obj)
{
return unary_plus_object_partfn_t<placeholder1_t, ObjT>(fn, obj);
}
We now can compile and run the second use case:
std::transform(vec.cbegin(), vec.cend(), std::ostream_iterator<int>(std::cout, " "), _1 + 5);
std::cout << std::endl;
which outputs:
9 -3 6 5 12
This is basically all that you need to do to solve the problem. Think about how you can write custom functional types, instances of which can be returned by overloads of operators.
EDIT: Improved the overloads of function call operators by employing pass-by-reference.
EDIT2: In some cases it will be necessary to store a reference to an object rather than a copy of it. For example, to accommodate std::cout << _1, you will need to store a reference to std::cout in the resulting functional object because the std::ios_base copy constructor is private, and it is impossible to copy construct objects of any class derived from std::ios_base including std::ostream.
To allow for std::cout << _1, you might want to write a ref_insert_unary_partfn_t template. Such a template, like the example of unary_plus_object_partfn_t above, would be templated on an object type and a unary functional type:
template <typename ObjT, typename UnaryFnT>
struct ref_insert_unary_partfn_t;
Instances of instantiations of this template will need to store a reference to an object of type ObjT as well as a copy of a unary functional object of type UnaryFnT:
template <typename ObjT, typename UnaryFnT>
struct ref_insert_unary_partfn_t
{
ObjT& m_ref;
UnaryFnT m_fn;
ref_insert_unary_partfn_t(ObjT& ref, UnaryFnT fn)
: m_ref(ref), m_fn(fn)
{
}
};
Add overloads of the function call operator as before as well as overloads of the insertion operator, <<.
In the case of std::cout << _1, the returned object would have the type ref_insert_unary_partfn_t<std::basic_ostream<char>, placeholder1_t>.
A simple example:
template <typename T>
class Parameter
{
};
template <typename T>
struct Ascending
{
bool operator()(T left, T right)
{
return left < right;
}
};
template <typename T>
Ascending<T> operator > (Parameter<T> p1, Parameter<T> p2)
{
return Ascending<T>();
}
int main()
{
std::vector<int> vec;
vec.push_back(3);
vec.push_back(6);
vec.push_back(7);
vec.push_back(2);
vec.push_back(7);
std::vector<int>::iterator a = vec.begin();
Parameter<int> _1;
Parameter<int> _2;
std::sort(a, a+4, _1 > _2);
}