fork(3) download
#include 
#include 

typedef  std::pair PairInt;

namespace std
{
template<>
bool operator < (const PairInt& l, const PairInt& r) 
{
    //swap only if they're unequal to avoid infinite recursion
    if (l.first != l.second) 
    {
         //swap elements, considering your special case
          if (l.first == r.second && l.second == r.first)
             return l < PairInt(r.second, r.first); //call again!
    }

   //actual comparison is done here
   if ( l.first != r.first )
        return l.first < r.first;
   else 
        return l.second < r.second;
}
}

int main()
{
    std::set intSet;
    intSet.insert(PairInt(1,3));
    intSet.insert(PairInt(1,4));
    intSet.insert(PairInt(1,4));
    intSet.insert(PairInt(4,1));
    for(auto it = intSet.begin(); it != intSet.end(); ++it)
           std::cout << it->first << "," << it->second  << std::endl;
}
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
1,3
1,4