On 09/07/2011 11:59 PM, Christophe wrote:
It is not. But there is currently no nice way to express a set of
orthogonal flags.
Well, you could use an array of flags ? Oh, wait, that is precisely what
"r", "w", "rw" would be.
At least it is short.
Another option is to use the power of typesafe variadic functions:
enum Mode :char { read, write }
File fOpen(string filename, Mode[]...);
auto file = fOpen("test.txt", Mode.read, Mode.write);
Isn't it much clearer than using (Mode.read | Mode.write)? Even using
explicitely [Mode.read, Mode.write] sounds safer anyway. It is uses more
memory that using bits operators, but who cares about few bytes when
opening a whole file ?
do you seriously prefer
auto f=fOpen("bah.txt",[Mode.read, Mode.write]);
over
auto f=fOpen("bah.txt","rw");
if that is the case, you could do
auto f=fOpen("bah.txt",encodeMode!([Mode.read, Mode.write]));
that even saves the few bytes.