May 20, 2005 Re: Second look static if and iftype... | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | Also, iftype enables picking apart of a type using the type deduction capability analogous to the template partial specialization rules. | |||
May 20, 2005 Re: Second look static if and iftype... | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <newshound@digitalmars.com> wrote in message news:d6k3hi$e1u$1@digitaldaemon.com... > Also, iftype enables picking apart of a type using the type deduction capability analogous to the template partial specialization rules. > Yep. And idea is good. But I think you aren't satisfied with the name too ... static if( ) is good. If we would have some distinctive notation for typenames and deductions then it will be possible to use something like : static if type(T:T[]) { ... } Ideas, anyone? | |||
May 20, 2005 Re: DMD 0.124 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> I'm not too sure about iftype. Let's see how it goes. Consider it
> 'experimental' for now.
>
> http://www.digitalmars.com/d/changelog.html
>
>
>
D is Looking great, Walter! Very nice new features.
Thanks!
-DavidM
| |||
May 20, 2005 Re: DMD 0.124 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > I'm not too sure about iftype. Let's see how it goes. Consider it > 'experimental' for now. > > http://www.digitalmars.com/d/changelog.html At the moment I don't see how this iftype (bar T) alias T S; else alias long S; is any more useful than this alias bar S; Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. | |||
May 20, 2005 Re: Second look static if and iftype... | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | > Err, I guess I didn't meant static if (rather if), as iftype isn't necessarily static, I suppose. non-static iftype (non-compile time) has no practical meaning. At runtime type must be known so no uncertainty (if) here. So it is compile time creature. To have two versions of 'static if ' we should have designator boolean/typename expression. E.g. cast expression accepts only typename so it could be parsed reliably. What about this then: static if cast(bar : int) // satisfied because short can be // implicitly converted to int printf("satisfied\n"); else printf("not satisfied\n"); ? BTW: C++ uses < > brackets for typename expressions (many grammatic problems), but static if in C++ could be written as static if <bar:int> ... else ... .... "Unknown W. Brackets" <unknown@simplemachines.org> wrote in message news:d6julq$8i7$1@digitaldaemon.com... > Err, I guess I didn't meant static if (rather if), as iftype isn't necessarily static, I suppose. > > -[Unknown] > > >> I'd also prefer a merge of "static if" and "iftype". I quite like static if, myself. I guess I'd push: >> >> static if (bar isimplicit int) >> static if (bar as T) >> static if (bar as T isimplicit int) >> >> Or something. Just seems : is a bit overused for various meanings. | |||
May 20, 2005 Re: DMD 0.124 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:d6kpfi$vtp$1@digitaldaemon.com... > Walter wrote: >> I'm not too sure about iftype. Let's see how it goes. Consider it 'experimental' for now. >> >> http://www.digitalmars.com/d/changelog.html > > At the moment I don't see how this > > iftype (bar T) > alias T S; > else > alias long S; > > is any more useful than this > > alias bar S; agreed. the "else" clause is dead code if I understand correctly. | |||
May 20, 2005 Third look on static if and iftype... | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | static if and especially iftype are in fact kind of anonymous template declaration and instantiation at one point.
Lets take a look on given example:
alias short bar;
int foo(bar x)
{
iftype (bar : int) // satisfied because short can be
// implicitly converted to int
printf("satisfied\n");
else
printf("not satisfied\n");
}
It is in fact:
int foo(bar x)
{
mixin Noname!(bar);
template Noname(T) { printf("not satisfied\n"); }
template Noname(T: int) { printf("satisfied\n"); }
}
Therefore if our intention is to move declaration and instantiation in one
point we might
use 'anonymous templates' :
int foo(bar x)
{
mixin template(bar: int)
{
printf("not satisfied\n");
}
mixin else
{
printf("satisfied\n");
}
}
Huh?
| |||
May 20, 2005 Re: Third look on static if and iftype... | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | Pluses of the approach ( 'mixin template' versus 'iftype' ) that I can write AND type expressions too
mixin(bar: int, foo: double) // if bar is int and foo is double
{
printf("satisfied\n");
}
mixin else
{
printf("not satisfied\n");
}
| |||
May 20, 2005 And my final look and proposal | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | 'Anonymous template declaration and instantiation'
to change 'static if' on
mixin if( BooleanExpression ) ... [ else .... ]
to change 'iftype' on
mixin when ( Type : TypeSpecialization ) [ else ... ]
formal definition of Mixins in the specification is below.
This will give us:
mixin when(foo: int)
printf("foo is like int") ;
else when (foo: double)
printf("foo is like double") ;
else
static assert( 0, " foo is neither int nor double" );
mixin if( n == 32 )
int x;
else if( n == 16 )
short x;
else
box x;
---------------------------------------------------------
formal definition of Mixins in the specification:
TemplateMixin:
mixin TemplateIdentifier ;
mixin TemplateIdentifier MixinIdentifier ;
mixin TemplateIdentifier !( TemplateArgumentList ) ;
mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ;
(static if)
mixin if( CompileTimeBooleanExpression ) StatementOrBlockDecl
mixin if( CompileTimeBooleanExpression ) StatementOrBlockDecl
[ else if( CompileTimeBooleanExpression ) StatementOrBlockDecl ]
else StatementOrBlockDecl
(iftype)
mixin when( Type : TypeSpecialization ) StatementOrBlockDecl
mixin when( Type : TypeSpecialization ) StatementOrBlockDecl
[ else when ( Type : TypeSpecialization ) StatementOrBlockDecl ]
else StatementOrBlockDecl
"Walter" <newshound@digitalmars.com> wrote in message news:d6imvd$2c53$1@digitaldaemon.com...
> I'm not too sure about iftype. Let's see how it goes. Consider it 'experimental' for now.
>
> http://www.digitalmars.com/d/changelog.html
>
>
>
| |||
May 20, 2005 Re: DMD 0.124 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <newshound@digitalmars.com> wrote in message news:d6imvd$2c53$1@digitaldaemon.com... > I'm not too sure about iftype. Let's see how it goes. Consider it 'experimental' for now. > > http://www.digitalmars.com/d/changelog.html Are there some motivating examples for "static if" and iftype? The doc example illustrate the behavior but don't do anything useful so I'm not sure when to use these constructs vs template specialization. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply