I want to use a std :: priority_queue container with a custom data-type and several comparison parameters (I I define a factor for each of them; each of them is working on the same type). The comparative criteria should be used to be configurable by using a function parameter (to avoid if_then_ initialization of the queue). Based on
, that, as far as I understand it, using a comparative doctor, which is introduced to itself, with one of the function functions defined, Tried to use a configurable comparable brain, which is initialized with another comparative functionor (which is stored locally and when used as it is used) ). I have not got to work yet.
I do not even know what I want to do in general. I do not know what type of thing I was messing about (I type typefide boost :: function XXX) or additional C ++ 0x features (what "closure" support?) Will be required.
So basically I want to do something like the following to work (it will not compile with a non-long but ugly error; GCC 4.5):
#include & lt; Iostream & gt; #include & lt; Queue & gt; # Include & lt; Boost / tuple / tuple.hpp & gt; # Include & lt; Boost / function.hpp & gt; Type-ff boost :: Tuple & LT; Double, int & gt; CUSTOM_TYPE; // Only examples! Typedef Promotion :: Work & lt; Bool (const custom_type & amp; l, const custom_type & amp; r) & gt; Comp_type; // Comparison Matercutter StructureFop_com {BULL operator () (CONST custom_type & amp; l, CONST custom_type & amp;; R) const {// ONLY id return l.get & lt; 1 & gt; () & Gt; R.get & lt; 1 & gt; (); }}; Struct lifo_comp {bool operator () (const custom_type & amp; l, const custom_type & amp; amp; r) {// only id return l.get & lt; 1 & gt; () & Lt; R.get & lt; 1 & gt; (); }}; Class {public: compare compare (const comp_type & amp; comp); Bull Operator () (Cons Custom_type & amp; l, Constant Custom_ Type & amp; R) {Return Component (L, R); } Private: const comp_type & amp; computer application; }; Some_Class_Using_Queue {public: some_Class_Using_Queue (comp_type & comp): pqueue (compare (comp)) {} zero test () {pqueue.push (custom_type (1.0, 1)); } Private: std :: priority_queue & lt; Custom_type, std :: vector & lt; Custom_type & gt; Compare & gt; Pqueue; }; Int main () {comp_type f = fifo_comp (); Some_Class_Using_Queue temp ((f)); // important temp.test (); Return 1; } - Any help (STL / Boost is encouraged to use) to work for me?
- Any better ideas (this is completely different)?
- Are Any Good C ++ 0x FEATURES HERE (HAPPENING HERE) HELP?
Thank you.
PS / Edit: I know, this is possible and it is easy to make the template templated and template -param as the appropriate comp class. But I do not know that this is a better way of doing this (about design) from this point of view, I need to switch / if-else before calling because of the ultimate need of template. PS: I set the "priority_jew" tag, even if the question is completely independent of this adapter-class. If someone wants to remove it, then just do it.
You are missing the definition of the creator of: Clear comp (const comp_type and comp): comp (comp) {} In addition, it creates and runs for me.
In addition, compare appears to be unusable, it wraps comp_type perfectly with a similar interface. After removing the Comparison class and after transferring it to comp_type , the code still creates and runs.
Comments
Post a Comment