Assuming I have a class that requires a custom comparator that is not known at compile time,
template <class T>
using Comparator = std::function<int(const T&, const T&)>;
class Foo {
public:
Foo(Comparator<T> cmp)
: cmp_{cmp}
{}
private:
Comparator cmp_;
};
and I want to allow for a more generalized comparator that allows for external state,
template <class T>
using uComparator = std::function<int(const T&, const T&, void *)>;
which of these options will lead to the least headaches in the future? (and do they even do what I expect them to do?)
template <class T>
Foo<T>::Foo(uComparator<T> ucmp, void *udata)
: cmp_{[ucmp, udata](const T& a, const T& b){ return ucmp(a, b, udata); }}
{}
template <class T>
Foo<T>::Foo(uComparator<T> ucmp, void *udata)
: cmp_{std::bind(ucmp, _1, _2, udata)}
{}
is there a better way to be going about this?