This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/48038] stable_sort problem with C++0x and comparator by value


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48038

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-09 10:24:42 UTC ---
slightly reduced ...

#include <vector>
#include <iostream>
#include<algorithm>

typedef std::vector<double> VI;

struct V {
   VI v;

   V(){std::cout <<"dc" << std::endl;}

   ~V(){std::cout <<"dd " << v.size()<< std::endl;}

   V(V const & rh) : v(rh.v) {
     std::cout <<"cc" << std::endl;
   }

   V(size_t n, double d) : v(n,d){} 


   V & operator=(V const &rh) {
     std::cout <<"ac" << std::endl;
     V tmp(rh);
     v.swap(tmp.v);
     return *this;
  }

   V(V && rh) : v(std::move(rh.v)) {
     std::cout <<"rc" << std::endl;
   }

   V & operator=(V && rh) {
     std::cout <<"ar" << std::endl;
     v = std::move(rh.v);
     return *this;
  }

};


inline bool operator<(V lh, V rh) {
  return lh.v.at(0) < rh.v.at(0);
}


int main()
{
   std::vector<V> vvs;
   vvs.push_back(V(1, 0.));
   vvs.push_back(V(1, 1.));
   vvs.insert(vvs.begin(),V(1, 2.));

   std::stable_sort(vvs.begin(), vvs.end());

}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]