If you're not actually responding to a post, please don't quote the entire thing in your message. Tim M wrote:What does this mean: module tconst; import std.stdio; invariant(char)[] func() { invariant(char)[] s = "hello"; return s; } void main() { auto s = func(); s[0] = 'm'; //error } I thought we already have returning const/invariant? That code ^ works fine for me.You missed the point. This has nothing to do with returning invariant types. Jason is proposing a way to create a function which maintains the const-ness of its arguments without having to implement multiple versions. In other words, return(T) max(return(T) a, return(T) b){ return (a>b)?a:b; } Would be similar to the following: T max(T a, T b){ return (a>b)?a:b; } const(T) max(const(T) a, const(T) b){ return (a>b)?a:b; } invariant(T) max(invariant(T) a, invariant(T) b){ return (a>b)?a:b; } Except that each would share a single implementation. -- Daniel
On Sun, 08 Mar 2009 19:18:52 +1300, Daniel Keep
<[email protected]> wrote:
- Returning const? -- A potential solution Jason House
- Re: Returning const? -- A potential solution Daniel Keep
- Re: Returning const? -- A potential solution Tim M
- Re: Returning const? -- A potential solution Daniel Keep
- Re: Returning const? -- A potential solutio... Tim M
- Re: Preserving const? -- A potential s... Tim M
- Re: Preserving const? -- A potenti... Daniel Keep
- Re: Preserving const? -- A pot... Tim M
- Re: Preserving const? -- A pot... Daniel Keep
- Re: Preserving const? -- A pot... Tim M
- Re: Preserving const? -- A pot... Daniel Keep
- Re: Virtual templated function... Tim M
- Re: Virtual templated function... Daniel Keep
- Re: Virtual templated function... Michel Fortin
- Re: Virtual templated function... Tim M
