C++ guys hate static_if?

deadalnix deadalnix at gmail.com
Thu Mar 14 10:37:11 PDT 2013


On Thursday, 14 March 2013 at 17:07:16 UTC, Andrei Alexandrescu 
wrote:
> Very simple. Traditionally there's two crucial epochs known as 
> compilation time and run time. (There's some minor distinctions 
> like link time etc.) The whole notion of concepts and other 
> type systems for templates is predicated on three crucial 
> epochs: library compilation time, library user compilation 
> time, and run time. The logic goes, someone writes a generic 
> library and wants to distribute it to users. Users shouldn't 
> ever see bugs caused by e.g. typos in the library.
>

I'm not sure if you are thinking I'm really stupid here.

> So the crowd that use meta-type systems is formed of library 
> writers who want to distribute libraries without ever 
> instantiating them. I don't think that's a good crowd to cater 
> for.
>
> I've been surprised to figure how many people don't get this 
> flow, or only have a vague image of it. Although meta-types are 
> arguably "the right thing" to do, they're a lot less attractive 
> once it's clear what scenarios they help.
>

Let me demonstrate with an actual example :

libd-llvm/libd/src/d/parser/ambiguous.d(126): Error: no property 
'bar' for type 'Lexer', did you mean 'r'?
libd-llvm/libd/src/d/parser/statement.d(392): Error: template 
instance 
d.parser.statement.parseStatement!(Lexer).parseStatement.parseDeclarationOrExpression!(__dgliteral27, 
Lexer) error instantiating
libd-llvm/libd/src/d/parser/statement.d(406):        instantiated 
from here: parseStatement!(Lexer)
libd-llvm/libd/src/d/parser/expression.d(652):        
instantiated from here: parseBlock!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(208):        instantiated 
from here: parsePrimaryExpression!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(83):        ... (11 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/statement.d(406): Error: template 
instance d.parser.statement.parseStatement!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/expression.d(652):        
instantiated from here: parseBlock!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(208):        instantiated 
from here: parsePrimaryExpression!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(83):        instantiated 
from here: parseTemplateArguments!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(22):        ... (10 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/expression.d(652): Error: template 
instance d.parser.statement.parseBlock!(Lexer) error instantiating
libd-llvm/libd/src/d/parser/dtemplate.d(208):        instantiated 
from here: parsePrimaryExpression!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(83):        instantiated 
from here: parseTemplateArguments!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(22):        instantiated 
from here: parseBuiltIdentifier!(Lexer)
libd-llvm/libd/src/d/parser/type.d(56):        ... (9 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(208): Error: template 
instance d.parser.expression.parsePrimaryExpression!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/identifier.d(83):        instantiated 
from here: parseTemplateArguments!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(22):        instantiated 
from here: parseBuiltIdentifier!(Lexer)
libd-llvm/libd/src/d/parser/type.d(56):        instantiated from 
here: parseIdentifier!(Lexer)
libd-llvm/libd/src/d/parser/type.d(16):        ... (8 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(83): Error: template 
instance d.parser.dtemplate.parseTemplateArguments!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/identifier.d(22):        instantiated 
from here: parseBuiltIdentifier!(Lexer)
libd-llvm/libd/src/d/parser/type.d(56):        instantiated from 
here: parseIdentifier!(Lexer)
libd-llvm/libd/src/d/parser/type.d(16):        instantiated from 
here: parseBasicType!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(112):        ... (7 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(22): Error: template 
instance d.parser.identifier.parseBuiltIdentifier!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/type.d(56):        instantiated from 
here: parseIdentifier!(Lexer)
libd-llvm/libd/src/d/parser/type.d(16):        instantiated from 
here: parseBasicType!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(112):        instantiated 
from here: parseType!(cast(ParseMode)0, Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(68):        ... (6 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/type.d(56): Error: template instance 
d.parser.identifier.parseIdentifier!(Lexer) error instantiating
libd-llvm/libd/src/d/parser/type.d(16):        instantiated from 
here: parseBasicType!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(112):        instantiated 
from here: parseType!(cast(ParseMode)0, Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(68):        instantiated 
from here: parseTypeParameter!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(46):        ... (5 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/type.d(16): Error: template instance 
d.parser.type.parseBasicType!(Lexer) error instantiating
libd-llvm/libd/src/d/parser/dtemplate.d(112):        instantiated 
from here: parseType!(cast(ParseMode)0, Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(68):        instantiated 
from here: parseTypeParameter!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(46):        instantiated 
from here: parseTemplateParameter!(Lexer)
libd-llvm/libd/src/d/parser/dfunction.d(51):        ... (4 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(112): Error: template 
instance d.parser.type.parseType!(cast(ParseMode)0, Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/dtemplate.d(68):        instantiated 
from here: parseTypeParameter!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(46):        instantiated 
from here: parseTemplateParameter!(Lexer)
libd-llvm/libd/src/d/parser/dfunction.d(51):        instantiated 
from here: parseTemplateParameters!(Lexer)
libd-llvm/libd/src/d/parser/declaration.d(362):        ... (3 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(68): Error: template 
instance d.parser.dtemplate.parseTypeParameter!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/dtemplate.d(46):        instantiated 
from here: parseTemplateParameter!(Lexer)
libd-llvm/libd/src/d/parser/dfunction.d(51):        instantiated 
from here: parseTemplateParameters!(Lexer)
libd-llvm/libd/src/d/parser/declaration.d(362):        
instantiated from here: parseFunction!(FunctionDeclaration, 
Lexer, string,Type)
libd-llvm/libd/src/d/parser/declaration.d(70):        ... (2 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(46): Error: template 
instance d.parser.dtemplate.parseTemplateParameter!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/dfunction.d(51):        instantiated 
from here: parseTemplateParameters!(Lexer)
libd-llvm/libd/src/d/parser/declaration.d(362):        
instantiated from here: parseFunction!(FunctionDeclaration, 
Lexer, string,Type)
libd-llvm/libd/src/d/parser/declaration.d(70):        
instantiated from here: parseTypedDeclaration!(Lexer)
libd-llvm/libd/src/d/parser/dmodule.d(40):        ... (1 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/dfunction.d(51): Error: template 
instance d.parser.dtemplate.parseTemplateParameters!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/declaration.d(362):        
instantiated from here: parseFunction!(FunctionDeclaration, 
Lexer, string,Type)
libd-llvm/libd/src/d/parser/declaration.d(70):        
instantiated from here: parseTypedDeclaration!(Lexer)
libd-llvm/libd/src/d/parser/dmodule.d(40):        instantiated 
from here: parseDeclaration!(Lexer)
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/declaration.d(362): Error: template 
instance d.parser.dfunction.parseFunction!(FunctionDeclaration, 
Lexer, string,Type) error instantiating
libd-llvm/libd/src/d/parser/declaration.d(70):        
instantiated from here: parseTypedDeclaration!(Lexer)
libd-llvm/libd/src/d/parser/dmodule.d(40):        instantiated 
from here: parseDeclaration!(Lexer)
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/declaration.d(70): Error: template 
instance d.parser.declaration.parseTypedDeclaration!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/dmodule.d(40):        instantiated 
from here: parseDeclaration!(Lexer)
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/dmodule.d(40): Error: template 
instance d.parser.declaration.parseDeclaration!(Lexer) error 
instantiating
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/base.d(14): Error: template instance 
d.parser.dmodule.parseModule!(Lexer) error instantiating
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
src/sdc/sdc.d(54): Error: template instance 
d.parser.base.parse!(Lexer) error instantiating
libd-llvm/libd/src/d/parser/ambiguous.d(126): Error: no property 
'bar' for type 'Lexer', did you mean 'r'?
libd-llvm/libd/src/d/parser/statement.d(392): Error: template 
instance 
d.parser.statement.parseStatement!(Lexer).parseStatement.parseDeclarationOrExpression!(__dgliteral27, 
Lexer) error instantiating
libd-llvm/libd/src/d/parser/statement.d(406):        instantiated 
from here: parseStatement!(Lexer)
libd-llvm/libd/src/d/parser/expression.d(652):        
instantiated from here: parseBlock!(Lexer)
libd-llvm/libd/src/d/parser/dtemplate.d(208):        instantiated 
from here: parsePrimaryExpression!(Lexer)
libd-llvm/libd/src/d/parser/identifier.d(83):        ... (11 
instantiations, -v to show) ...
libd-llvm/libd/src/d/parser/base.d(14):        instantiated from 
here: parseModule!(Lexer)
src/sdc/sdc.d(54):        instantiated from here: parse!(Lexer)
libd-llvm/libd/src/d/parser/statement.d(406): Error: template 
instance d.parser.statement.parseStatement!(Lexer) error 
instantiating
make: *** [bin/sdc] Erreur 1

Yes I added the bar on purpose in some heavily templated code. 
You concentrate too much on theses people that want to ship code 
without using it. They'll do it anyway.

And that make even more sense from the lib user perspective, as 
having the compiler vomit kilometers of internals of a lib is 
usually not helpful (this happen a lot with phobos).


More information about the Digitalmars-d mailing list