templates - C++ templated container class: How to best support both ordered and un-ordered item types? -


I am writing a templated C ++ generic container class which alternately creates its content in a well defined order Can keep Earlier this function pointer was used so that its contents can be ordered in a specific way in a specific manner, but I am trying to use templated functor arguments to replace it.

Since it is often done that the class users place different types of sorted items in separate containers, the container class takes an optional template argument that users Alternatively, your own comparative physician specifies:

  template  ItemType, compare the category: Factor type = comparisonfactory & lt; Item type & gt; & Gt; Class MyContainer {[...]};  

If the class user does not specify a custom mixer type, then it uses the following comparisonfactor definition from the default:

  template & lt; Typename itemtype & gt; Compare to the category Factor {public: Bull izitem lathesan (Const. Item type and a, cost item type) & amp; B) Cost {Return (A and LT; B); // will only compile for the type & lt; Operator}};  

This works very well for underlying types and user-defined types where at least the operator is defined. However, I would like to automatically do this for such type of work where there is no built-in or clearly defined operator, for those types, the order of objects within the container is not necessary.

The motivation is that I use this container to capture various types of different types and most of the time I do not care about the order of container types, but in some cases I did I do not want to ... and all kinds of operators of all types do not want to be less than "dummy", so I can use it with this container class ... and I have a custom "d I do not want to relate to "every time, when I use the table to store forum items that are not less operators.

So, there is a way I can use template specialization (or something) so that the default comparison factor (shown above) is used whenever possible, but in those cases where the factor is a factor The cause of the error would be, C ++ automatically resembles a "dummy" FallbackCompareFunctor one below? Or maybe there is some other clever way to handle this dilemma?

  template & lt; Typename itemtype & gt; Class Fallback Comparfactor {Public: Bull izitem lathesan (cost item type and a, cost item type) & amp; B) Const (Returns (A & A) <(and B)); // will compile for all types (useful for type where command is not important)}};  

For a default canceled case, a tap comparison factor, Use incorrect cases to use
You can then use the template std :: less () in your classified container.

  template & lt; Class T & gt; Composition Faucet Compaired: Public Binary_Function & lt; T, T, Balls & gt; {Bull Operator () (CONST T & amp; L, CONST T & R) CONST // edit: First "Return True;" What is wrong. return false; }}; Template & lt; Square t, class = compare = nullcompare & lt; T & gt; & Gt; Class MyContainer {[...]}; Template & lt; Class t, class = compare = std :: low & lt; T & gt; & Gt; Class MySortedContainer: Public MyContainer & lt; T, comparison & gt; {[...]};  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -