std.path.buildPath() and string enumeration

bearophile bearophileHUGS at lycos.com
Wed May 30 11:49:38 PDT 2012


nrgyzer:

> Is this a bug in std.path.buildPath() or is there anything I'm 
> doing wrong?

The signature of buildPath is:

immutable(C)[] buildPath(C)(const(C[])[] paths...);

But your inputs aren't of the same type. Named enum create their 
own type. You give buildPath a type string and a type path, that 
is not a string.

There are various solutions, this compiles, but it's not very 
safe:

buildPath(cast(string)path.log1, subDirectory);

Another solution is to not use a named enum:

enum : string {
     path_log1 = "/var/log1",
     path_log2 = "/var/log2"
}

buildPath(path_log1, subDirectory)

In bugzilla I have asked for an enum property that returns the 
raw value&type of an enum.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list