www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - isValidBinaryOp doesn't compile

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
In the post

http://forum.dlang.org/thread/bug-6384-3 http.d.puremagic.com/issues/

I tried to compile

template isValidBinaryOp(T1, string op, T2) {
    alias isValidBinaryOp = is(mixin("T1.init" ~ op ~ "T2.init") : 
bool);
}

but it fails as

/home/per/Work/cognia/t_geom.d(80): Error: basic type expected, 
not is
/home/per/Work/cognia/t_geom.d(80): Error: semicolon expected to 
close alias declaration
/home/per/Work/cognia/t_geom.d(80): Error: Declaration expected, 
not 'is'

What is wrong?
Sep 14 2013
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 9/14/13, "Nordl=F6w" <per.nordlow gmail.com> wrote:
 In the post

 http://forum.dlang.org/thread/bug-6384-3 http.d.puremagic.com/issues/

 I tried to compile

 template isValidBinaryOp(T1, string op, T2) {
     alias isValidBinaryOp =3D is(mixin("T1.init" ~ op ~ "T2.init") :
 bool);
 }

 What is wrong?

Use "enum isValidBinaryOp =3D is..". Aliases are used to create symbols which refer to other symbols but not to values.
Sep 14 2013
prev sibling next sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 09/14/13 22:45, "Nordlöw" wrote:
 In the post
 
 http://forum.dlang.org/thread/bug-6384-3 http.d.puremagic.com/issues/
 
 I tried to compile
 
 template isValidBinaryOp(T1, string op, T2) {
    alias isValidBinaryOp = is(mixin("T1.init" ~ op ~ "T2.init") : bool);
 }
 
 but it fails as
 
 /home/per/Work/cognia/t_geom.d(80): Error: basic type expected, not is
 /home/per/Work/cognia/t_geom.d(80): Error: semicolon expected to close alias
declaration
 /home/per/Work/cognia/t_geom.d(80): Error: Declaration expected, not 'is'
 
 What is wrong?

'is()' returns a value, not a type. Also, a binary op does not necessarily have to result in a type that implicitly converts to 'bool. template isValidBinaryOp(T1, string op, T2) { enum isValidBinaryOp = is(typeof(mixin("T1.init" ~ op ~ "T2.init"))); } artur
Sep 14 2013
prev sibling parent =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
Thx.
Sep 15 2013