STL std::map dynamic ordering
<p>I know this may be a silly question. but stil i have a confusion. 
W.r.t std::map. i have written a custom predicate for dymanic ordering of map, </p>

<pre><code>enum OrderingType 
{
    ASCENDING, 
    DESCENDING 
};

template &lt;class T&gt;
class Ordering
{
    OrderingType m_order;

public:
    Ordering(OrderingType order) : m_order(order) { }

    bool operator() (const T &amp;obj1, const T &amp;obj2)
    {
        if( m_order == ASCENDING )
            return obj1 &lt; obj2;

        if( m_order == DESCENDING )
            return obj1 &gt; obj2;
    } 
};
</code></pre>

<p>Advantage is</p>

<ol>
<li><p>We can decide the ordering of data elements in the map on some conditions   </p>

<p>OrderType type = (condition ? ASCENDING : DESCENDING ); 
   CUSTOMMAP m(type);</p></li>
<li><p>We can use same forward iterator for both ascending &amp; descending ordered map</p>

<p>in the below code. map's ordering works fine in both ascending &amp; descending order ( amp1 &amp; map2 ). But on assignment map2 = map1, the ordering of map2 changes along with the content. I was expected to copy only content, not the change in the ordering. further inserts on map2 ( which was declared as descending) will be in ascending order.</p></li>
</ol>

<p><strong>Any suggestions or idea..? or defining two way ordering predicate for map is bad idea..?</strong></p>

<pre><code>typedef map&lt;int, int, Ordering&lt;int&gt; &gt;  CUSTOMMAP;
typedef CUSTOMMAP::iterator       CUSTOMMAP_ITER;
typedef CUSTOMMAP::const_iterator CUSTOMMAP_CONST_ITER;

ostream&amp; operator &lt;&lt;(ostream&amp; out, const CUSTOMMAP&amp; mapobj)
{
    CUSTOMMAP_CONST_ITER citer = mapobj.begin();
    for( ; citer != mapobj.end(); ++citer )
    {
        out &lt;&lt; citer-&gt;first &lt;&lt; "   " &lt;&lt; citer-&gt;second &lt;&lt; endl;
    } 
    out &lt;&lt; "==========" &lt;&lt; endl;
    return out;
}

int main()
{
    CUSTOMMAP map1(ASCENDING);     //instantiate a map with ascending sorting
    CUSTOMMAP map2(DESCENDING);    //instantiate a map with descending sorting

    map1.insert( make_pair(1, 0));
    map1.insert( make_pair(2, 0));
    cout &lt;&lt; map1;                  // prints data in ascnding manner 

    map2.insert( make_pair(5, 0));
    map2.insert( make_pair(6, 0));
    cout &lt;&lt; map2;                  // prints data in descending manner 

    map2 = map1;

    cout &lt;&lt; map2;                  //copys contents of map1 to map2 &amp; changes 
                                   //map2's ordering predicate
    return 0;
}
</code></pre>
