News for hackers. Stuff that matters.
Re:An Introduction to Reflection in C++ by maccard on Saturday April 15, 2017 @07:32PM (#14123439)
How do you handle mode as a swap for something like a socket, or a file handle in that case?
Re:An Introduction to Reflection in C++ by MaulingMonkey on Saturday April 15, 2017 @07:49PM (#14123496)
These typically have null-like states in C++. If we were making a std::ifstream clone without templates inheritence, etc. we might write...

  class ifstream {
    FILE* f;
    ifstream(const ifstream&) = delete;
    ifstream& operator=(const ifstream&) = delete;
  public:
    ifstream(): f() {}
    explicit ifstream(const char* path): f(fopen(path, "rb")) {}
    ~ifstream() { if (f) fclose(f); }
    
    ifstream(ifstream&& original): f() {
      std::swap(f, original.f);
    }
    
    ifstream& operator=(ifstream&& original) {
      std::swap(f, original.f);
      return *this;
    }
    
    // ...
  };
This is very similar to the common pattern of implementing vanilla assignment in terms of copy construction and a swap.

EDIT: Added deleted copy ctor/assignment ops because I'm not a savage.

Re:An Introduction to Reflection in C++ by asveikau on Saturday April 15, 2017 @10:08PM (#14123973)
In the move constructor of the object wrapping an open file, swap the integer descriptors.