Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class A {
- public:
- // A() {}
- A(string name) : _name(name) { printName(__PRETTY_FUNCTION__); }
- ~A() { printName(__PRETTY_FUNCTION__); }
- // 拷贝构造函数
- A(const A &other) { _name += ":copyfrom-" + other._name; printName(__PRETTY_FUNCTION__); }
- // 赋值运算符
- A& operator=(const A &other) {
- if (this != &other) {
- _name += ":assignfrom-" + other._name;
- printName(__PRETTY_FUNCTION__);
- }
- return *this;
- }
- // 移动构造函数
- A(A &&other) { _name += ":movefrom-" + other._name; printName(__PRETTY_FUNCTION__); }
- // 移动赋值运算符
- A& operator=(A &&other) {
- if (this != &other) {
- _name += ":moveassignfrom-" + other._name;
- printName(__PRETTY_FUNCTION__);
- }
- return *this;
- }
- string _name = "anno";
- private:
- void printName(string funcName) { cout << _name << "\t" << funcName << endl; }
- };
- int main()
- {
- std::vector<A> vec {std::string("22"), std::string("11")};
- std::cout << "sort begin==================\n";
- std::sort(vec.begin(), vec.end(), [](const A& lhs, const A& rhs) {
- return lhs._name < rhs._name;
- });
- std::cout << "sort end==================\n";
- for (const auto &ele : vec) {
- std::cout << ele._name << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement