mercredi 25 novembre 2015

Interface designs of std::basic_fstream and std::unique_lock

I'm comparing the two classes, because they both associate with something else. std::basic_fstream has to associate with a file, while std::unique_lock has to associate with a mutex. As such, providing an open() method seems reasonable. Still, std::unique_lock provides no such methods. Lazy initialization can be performed anyway via move assignment. It may thus seem redundant to provide an open() method. std::basic_fstream, on the other hand, does provide an open() method. std::basic_fstream exists before C++11, and it is the only way to perform lazy initialization then. Putting aside backward compatibility considerations, would std::basic_fstream::open() just be removed? Or it still needs to be there for the operation may fail actually? Note that, the open (associate) operation always succeeds with std::unique_lock (not to be confused with the lock operation).

Aucun commentaire:

Enregistrer un commentaire