const Propagation
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon Dec 29 07:53:25 PST 2014
On 12/29/14 10:36 AM, Julian Kranz wrote:
> On Monday, 29 December 2014 at 15:25:13 UTC, Daniel Kozak wrote:
>> On Monday, 29 December 2014 at 15:17:30 UTC, Julian Kranz wrote:
>>> Thank you for your answers. All of your suggestions go into the right
>>> direction, however there's still one thing left that breakes it: the
>>> method itself (blah()) needs to be marked as const to be callable on
>>> a const object. Therefore, I need something like
>>>
>>> void blah(...)(...) if(this ia const object) const : nothing {
>>> }
Not in my solution, because blah is not a "method". T will become const
if the callee is const. As I said, you may have to do T : const(Hugo).
>>>
>>
>> Did you try my solutions? It doesn`t need blah to be const
>
> Uuuhm, you're right, it works :-D I don't completely understand why the
> compiler does not require the function to be sonst any longer...
I think Daniel's solution would work if the compiler infers const. I'm
not sure that it does, but if it works, it does :)
The compiler can infer attributes if a function is a template. Not all
attributes, but some of them.
-Steve
More information about the Digitalmars-d
mailing list