#define GenShellSortForField(FIELD)template<typename TYPE> \
void shellSortForField_##FIELD(vector<TYPE>&arr,int size) \
{ \
int step=size/2; \
while(step>0) \
{ \
for(int i=0;i<size-step;i++) \
{ \
int j=i; \
while(j>=0&&arr[j].FIELD>arr[j+step].FIELD) \
{ \
std::swap(arr[j],arr[j+step]); \
j--; \
} \
} \
step/=2; \
} \
}
...
GenShellSortForField(x);
#include <iostream>
struct A
{
int field;
};
template <typename T, typename Cmp>
void f(T const&a, T const&b, Cmp const &cmp)
{
if (cmp(a, b))
std::cout << "Less" << std::endl;
else
std::cout << "Eq or more" << std::endl;
}
int main()
{
A a = {2};
A b = {1};
f(a, b, [](A const &left, A const &right){return left.field < right.field;});
}