fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <tuple>
  4. #include <set>
  5. using namespace std;
  6.  
  7. class ScannedFile
  8. {
  9.  
  10. public:
  11. std::wstring old_name{ L"" };
  12. mutable std::wstring new_name{ L"" };
  13. mutable bool is_fv{ true };
  14.  
  15. ScannedFile() {}
  16.  
  17. ScannedFile(const std::wstring &old_n, const std::wstring &new_n, const std::string &ext) :
  18. old_name(old_n), new_name(new_n), extension(ext)
  19. {
  20. if(new_n.empty())
  21. this->SetDefaultNewName();
  22. }
  23.  
  24. ScannedFile(const std::wstring &old_n, const std::wstring &new_n) :
  25. old_name(old_n), new_name(new_n)
  26. {
  27. if (new_n.empty())
  28. this->SetDefaultNewName();
  29. this->extension = "";
  30. }
  31.  
  32. // ...
  33.  
  34. void SetDefaultNewName() const
  35. {
  36. this->new_name = L"pusta_nazwa" + std::to_wstring(counter++);
  37. }
  38.  
  39. bool operator<(const ScannedFile &f) const
  40. {
  41. return std::tie(this->old_name, this->new_name) < std::tie(f.old_name, f.new_name);
  42. }
  43.  
  44. private:
  45. static int counter;
  46. std::string extension;
  47. };
  48.  
  49. int ScannedFile::counter = 0;
  50.  
  51. int main() {
  52. auto files = set<ScannedFile> {ScannedFile(L"001", L""), ScannedFile(L"002", L"")};
  53.  
  54. if(!files.insert(ScannedFile(L"001", L"")).second)
  55. cout << "not inserted" << endl;
  56. else
  57. cout << "insertion succedded" << endl;
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
insertion succedded