c++ - use a run-time value in template instantiation -


please consider class a, , function object a_less. a_less compares 2 a pointers, depending on result of a::getvalue().

class {     int getvalue(const string &parameter); };  struct a_less : public binary_function<a *, *, bool> {     a_less(const string &p) : parameter(p) { }     bool operator()(const *lhs, const *rhs) const {         return a->getvalue(parameter) < rhs->getvalue(parameter);     }     string parameter; } 

how go declaring/creating sorted containers (sets, priority_queues, ...), of a pointers, sorted a_less depending on specific (run-time) values of parameter?

like this:

std::string p = ...; std::set<a,a_less> m(a_less(p)); 

you have specify template parameter compare (which 2nd set). when constructing map, need give comparison function object constructor of map.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -