const Propagation

Julian Kranz via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 29 08:48:45 PST 2014


On Monday, 29 December 2014 at 16:13:03 UTC, Vlad Levenfeld wrote:
> On Monday, 29 December 2014 at 16:03:41 UTC, Julian Kranz wrote:
>> On Monday, 29 December 2014 at 15:53:25 UTC, Steven 
>> Schveighoffer wrote:
>>> The compiler can infer attributes if a function is a 
>>> template. Not all attributes, but some of them.
>>>
>>> -Steve
>>
>> Ah, thanks, this explains it ;-). However, it's kind of uncool 
>> that this only works for templates...
>
> I've gotten into the habit of templating every function, even 
> if its a zero-parameter template, because trying to manage all 
> the pure/safe/const/nothrow annotations myself always winds up 
> putting me in a corner once the code starts to grow. It's not 
> so bad, really, one advantage is that you can define functions 
> that may or may not compile, but will only trigger an error if 
> they are called on a type that doesn't support it. You can 
> issue compile time branches using "static if (is 
> (typeof(function_name)))" to gain an extra degree of control 
> over this process.

Is that really cool? I mean, is wise to have the compiler treat 
templates and non-templates differently? C++ has tons of such 
inconsistencies which is the main reason I don't really like 
C++...


More information about the Digitalmars-d mailing list