the following is a bit of a mess and needs some refactoring work, but you

can use it like this:

struct Annotation{... int page_; ...int Length(){...}};

std::list<Annotation>::iterator toInsert =

std::lower_bound( m_annot.begin(), m_annot.end(),

a,

MakeEvaluator(&Annotation::page_)

);

vector<Annotation> aVec;

or

std::sort(aVec.begin(), aVec.end(), MakeEvaluator(&Annotation::Length));

#ifndef MEMBEREVALUATOR_H_

#define MEMBEREVALUATOR_H_

template<class objT, class valT>

struct EvaluateData

{

typedef valT (objT::*memPtrT);

typedef objT objType;

typedef valT valType;

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr);}

};

template<class objT, class valT>

struct Evaluate0

{

typedef valT (objT::*memPtrT)();

typedef objT objType;

typedef valT valType;

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)();}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)();}

};

template<class objT, class valT, class p1T>

struct Evaluate1

{

typedef valT (objT::*memPtrT)(p1T);

typedef objT objType;

typedef valT valType;

p1T p1_;

Evaluate1(p1T p1):p1_(p1){}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_);}

};

template<class objT, class valT, class p1T, class p2T>

struct Evaluate2

{

typedef valT (objT::*memPtrT)(p1T, p2T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

Evaluate2(p1T p1, p2T p2):p1_(p1), p2_(p2){}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_);}

};

template<class objT, class valT,class p1T, class p2T, class p3T>

struct Evaluate3

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

Evaluate3(p1T p1, p2T p2, p3T p3):p1_(p1), p2_(p2), p3_(p3){}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_);}

};

template<class objT, class valT, class p1T, class p2T, class p3T, class p4T>

struct Evaluate4

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

Evaluate4(p1T p1, p2T p2, p3T p3, p4T p4):p1_(p1), p2_(p2), p3_(p3),

p4_(p4){}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_);}

};

template<class objT, class valT, class p1T, class p2T, class p3T, class p4T,

class p5T>

struct Evaluate5

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

p5T p5_;

Evaluate5(p1T p1, p2T p2, p3T p3, p4T p4, p5T p5)

:p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5)

{}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_, p5_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_, p5_);}

};

template<class objT, class valT,

class p1T, class p2T, class p3T, class p4T, class p5T, class p6T>

struct Evaluate6

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T, p6T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

p5T p5_;

p6T p6_;

Evaluate6(p1T p1, p2T p2, p3T p3, p4T p4, p5T p5, p6T p6)

:p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6)

{}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_, p5_, p6_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_, p5_, p6_);}

};

template<class objT, class valT,

class p1T, class p2T, class p3T, class p4T, class p5T, class p6T, class

p7T>

struct Evaluate7

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T, p6T, p7T);

typedef objT objType;

typedef valT valType;

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T, p6T, p7T);

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

p5T p5_;

p6T p6_;

p7T p7_;

Evaluate7(p1T p1, p2T p2, p3T p3, p4T p4, p5T p5, p6T p6, p7T p7)

:p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6), p7_(p7)

{}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_, p5_, p6_, p7_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_, p5_, p6_, p7_);}

};

template<class objT, class valT,

class p1T, class p2T, class p3T, class p4T, class p5T, class p6T,

class p7T, class p8T>

struct Evaluate8

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T, p6T, p7T, p8T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

p5T p5_;

p6T p6_;

p7T p7_;

p8T p8_;

Evaluate8(p1T p1, p2T p2, p3T p3, p4T p4, p5T p5, p6T p6, p7T p7, p8T p8)

:p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6), p7_(p7), p8_(p8)

{}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_, p5_, p6_, p7_, p8_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_, p5_, p6_, p7_, p8_);}

};

template<class objT, class valT,

class p1T, class p2T, class p3T, class p4T, class p5T, class p6T,

class p7T, class p8T, class p9T>

struct Evaluate9

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T, p6T, p7T, p8T, p9T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

p5T p5_;

p6T p6_;

p7T p7_;

p8T p8_;

p9T p9_;

Evaluate9(p1T p1, p2T p2, p3T p3, p4T p4, p5T p5, p6T p6, p7T p7, p8T p8,

p9T p9)

:p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6), p7_(p7), p8_(p8),

p9_(p9)

{}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_, p5_, p6_, p7_, p8_, p9_);}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_, p5_, p6_, p7_, p8_, p9_);}

};

template<class objT, class valT,

class p1T, class p2T, class p3T, class p4T, class p5T, class p6T,

class p7T, class p8T, class p9T, class p10T>

struct Evaluate10

{

typedef valT (objT::*memPtrT)(p1T, p2T, p3T, p4T, p5T, p6T, p7T, p8T, p9T,

p10T);

typedef objT objType;

typedef valT valType;

p1T p1_;

p2T p2_;

p3T p3_;

p4T p4_;

p5T p5_;

p6T p6_;

p7T p7_;

p8T p8_;

p9T p9_;

p10T p10_;

Evaluate10(p1T p1, p2T p2, p3T p3, p4T p4, p5T p5, p6T p6, p7T p7, p8T p8,

p9T p9, p10T p10)

:p1_(p1), p2_(p2), p3_(p3), p4_(p4), p5_(p5), p6_(p6), p7_(p7), p8_(p8),

p9_(p9), p10_(p10)

{}

valT evaluate(const objT& obj, memPtrT ptr) const {return (obj.*ptr)(p1_,

p2_, p3_, p4_, p5_, p6_, p7_, p8_, p9_, p10_);}

valT evaluate(const objT& obj, memPtrT ptr){return (obj.*ptr)(p1_, p2_,

p3_, p4_, p5_, p6_, p7_, p8_, p9_, p10_);}

};

template<class evalT>

struct ComparerAndEvaluator

{

evalT eval_;

evalT::memPtrT ptr_;

typedef evalT::objType argument_type;

bool operator()(const evalT::objType& ls, const evalT::objType& rs){ return

eval_.evaluate(ls, ptr_) < eval_.evaluate(rs, ptr_);}

evalT::valType operator()(const evalT::objType& obj){return

eval_.evaluate(obj, ptr_);}

evalT::valType operator()(const evalT::objType& obj) const {return

eval_.evaluate(obj, ptr_);}

ComparerAndEvaluator(evalT eval, evalT::memPtrT ptr):eval_(eval),

ptr_(ptr){}

};

template<class T, class valT>

ComparerAndEvaluator<EvaluateData<T, valT> >

MakeEvaluator(valT (T::*pmem))

{

return ComparerAndEvaluator<EvaluateData<T, valT> >(EvaluateData<T,

valT>(), pmem);

}

template<class T, class valT>

ComparerAndEvaluator<Evaluate0<T, valT> >

MakeEvaluator(valT (T::*pmem)())

{

return ComparerAndEvaluator<Evaluate0<T, valT> >(Evaluate0<T, valT>(),

pmem);

}

template<class T, class valT, class p1T>

ComparerAndEvaluator<Evaluate1<T, valT, p1T> >

MakeEvaluator(valT (T::*pmem)(p1T), p1T p1)

{

typedef Evaluate1<T, valT, p1T> Evaluator;

return ComparerAndEvaluator<Evaluator>(Evaluator(p1), pmem);

}

template<class T, class valT, class p1T, class p2T>

ComparerAndEvaluator<Evaluate2<T, valT, p1T, p2T> >

MakeEvaluator(valT (T::*pmem)(p1T, p2T), p1T p1, p2T p2)

{

typedef Evaluate2<T, valT, p1T, p2T> Evaluator;

return ComparerAndEvaluator<Evaluator>(Evaluator(p1, p2), pmem);

}

template<class T, class valT, class p1T, class p2T, class p3T>

ComparerAndEvaluator<Evaluate3<T, valT, p1T, p2T, p3T> >

MakeEvaluator(valT (T::*pmem)(p1T, p2T, p3T), p1T p1, p2T p2, p3T p3)

{

typedef Evaluate3<T, valT, p1T, p2T, p3T> Evaluator;

return ComparerAndEvaluator<Evaluator>(Evaluator(p1, p2, p3), pmem);

}

template<class T, class valT, class p1T, class p2T, class p3T, class p4T>

ComparerAndEvaluator<Evaluate4<T, valT, p1T, p2T, p3T, p4T> >

MakeEvaluator(valT (T::*pmem)(p1T, p2T, p3T, p4T), p1T p1, p2T p2, p3T p3,

p4T p4)

{

typedef Evaluate4<T, valT, p1T, p2T, p3T, p4T> Evaluator;

return ComparerAndEvaluator<Evaluator>(Evaluator(p1, p2, p3, p4), pmem);

}

template<class T, class valT, class p1T, class p2T, class p3T, class p4T,

class p5T>

ComparerAndEvaluator<Evaluate5<T, valT, p1T, p2T, p3T, p4T, p5T> >

MakeEvaluator(valT (T::*pmem)(p1T, p2T, p3T, p4T, p5T), p1T p1, p2T p2, p3T

p3, p4T p4, p5T p5)

{

typedef Evaluate5<T, valT, p1T, p2T, p3T, p4T, p5T> Evaluator;

return ComparerAndEvaluator<Evaluator>(Evaluator(p1, p2, p3, p4, p5),

pmem);

}

template<class T, class valT, class p1T, class p2T, class p3T, class p4T,

class p5T, class p6T>

ComparerAndEvaluator<Evaluate6<T, valT, p1T, p2T, p3T, p4T, p5T, p6T> >

MakeEvaluator(valT (T::*pmem)(p1T, p2T, p3T, p4T, p5T, p6T), p1T p1, p2T p2,

p3T p3,

p4T p4, p5T p5, p6T p6)

{

typedef Evaluate6<T, valT, p1T, p2T, p3T, p4T, p5T, p6T> Evaluator;

return ComparerAndEvaluator<Evaluator>(Evaluator(p1, p2, p3, p4, p5, p6),

pmem);

}

template<class T, class valT, class p1T, class p2T, class p3T, class p4T,

class p5T, class p6T, class p7T>

...

**read more »**