std.path.buildPath() and string enumeration

Artur Skawina art.08.09 at gmail.com
Wed May 30 12:39:09 PDT 2012


On 05/30/12 20:34, nrgyzer wrote:
> Hi,
> 
> I've the following enumeration:
> 
> enum path : string {
> 
>   log1 = "/var/log1",
>   log2 = "/var/log2"
> 
> }
> 
> Now... when I try to do the following:
> 
> string subDirectory = "example";
> 
> string newPath = buildPath(path.log1, subDirectory);
> 
> I get the following errors:
> 
> Error: template std.path.buildPath does not match any function template
> declaration
> Error: template std.path.buildPath(C) if (isSomeChar!(C)) cannot deduce
> template function from argument types !()(path,string)
> Error: template std.path.buildPath does not match any function template
> declaration
> Error: template std.path.buildPath(C) if (isSomeChar!(C)) cannot deduce
> template function from argument types !()(path,string)
> 
> Is this a bug in std.path.buildPath() or is there anything I'm doing wrong?
> 

A bug, as an enum member is supposed to implicitly convert to its base type. [1]

You might be able to work-around it like this

   template _path() {
      enum : string {
        log1 = "/var/log1",
        log2 = "/var/log2"
      }
   }
   alias _path!() path;

artur

[1] Actually, D's "typesafe variadic functions" don't play well with certain
other features too, eg

   void f(A...)(A a) {}
   void f()(string[] a...) {}
   f("a", "b"); // expecting the second overload to be called is reasonable,
                // but this isn't what's going to happen.



More information about the Digitalmars-d-learn mailing list