How to sort array using Sort, or Array.Sort(predicate) ?
I have defined Predicate like this:
bool ARPGItem::ConstituionPredicate(const ARPGItem& ip1, const ARPGItem& ip2)
{
return ip1.Attributes.Constitution < ip2.Attributes.Constitution;
}
And now I’m trying to use it with sort:
Sort(EquipedItems[0], EquipedItems.Num(), &ARPGItem::ConstituionPredicate);
Or with Array:
EquipedItems.Sort(&ARPGItem::ConstituionPredicate);
Array hold objects of type ARPGItem.
And I get big error:
1> D:\Unreal\Rocket\Engine\Source\Runtime\Core\Public\Templates\Sorting.h(58) : while compiling class template member function 'bool TDereferenceWrapper::operator ()(ARPGItem *,ARPGItem *) const'
1> with
1> [
1> T=ARPGItem *,
1> PREDICATE_CLASS=bool (__cdecl ARPGItem::* )(const ARPGItem &,const ARPGItem &)
1> ]
1> D:\Unreal\Rocket\Engine\Source\Runtime\Core\Public\Templates\Sorting.h(101) : see reference to function template instantiation 'bool TDereferenceWrapper::operator ()(ARPGItem *,ARPGItem *) const' being compiled
1> with
1> [
1> T=ARPGItem *,
1> PREDICATE_CLASS=bool (__cdecl ARPGItem::* )(const ARPGItem &,const ARPGItem &)
1> ]
1> D:\Unreal\Rocket\Engine\Source\Runtime\Core\Public\Templates\Sorting.h(185) : see reference to class template instantiation 'TDereferenceWrapper' being compiled
1> with
1> [
1> T=ARPGItem *,
1> PREDICATE_CLASS=bool (__cdecl ARPGItem::* )(const ARPGItem &,const ARPGItem &)
1> ]
1> D:\Unreal\Rocket\Engine\Source\Runtime\Core\Public\Containers\Array.h(1419) : see reference to function template instantiation 'void Sort(T **,const int32,const PREDICATE_CLASS &)' being compiled
1> with
1> [
1> PREDICATE_CLASS=bool (__cdecl ARPGItem::* )(const ARPGItem &,const ARPGItem &),
1> T=ARPGItem
1> ]
1> D:\Unreal\RPG\Source\RPG\Components\RPGEquipmentManagerComponent.cpp(148) : see reference to function template instantiation 'void TArray::Sort(const PREDICATE_CLASS &)' being compiled
1> with
1> [
1> InElementType=ARPGItem *,
1> PREDICATE_CLASS=bool (__cdecl ARPGItem::* )(const ARPGItem &,const ARPGItem &)
1> ]
1> D:\Unreal\RPG\Source\RPG\Components\RPGEquipmentManagerComponent.cpp(148) : see reference to function template instantiation 'void TArray::Sort(const PREDICATE_CLASS &)' being compiled
1> with
1> [
1> InElementType=ARPGItem *,
1> PREDICATE_CLASS=bool (__cdecl ARPGItem::* )(const ARPGItem &,const ARPGItem &)
1> ]
I’ve been looking trough Sorting.h and Array.h, but there is nothing about how predicate should be declared, where it should be defined, or how it should be used…
So I assumed it is used in similar manner to predicate for std::vector, but seems it is not the case.