Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 29, 2007 Const function | ||||
---|---|---|---|---|
| ||||
(... start a new thread because I just don't know who to reply to) Many posts about const/invariant talk about the "problem" of defining const functions. Some think we should indicate constness at the end of the function declaration, but it is also possible to do it at the front. So, as far as I understand it, there are two ways to express function constness for now: const int foo(); int foo() const; To my mind, both solutions are unintuitive. I would expect something like that: int const foo(); Is there any big argument against this? |
December 02, 2007 Re: Const function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gilles G. | On Thu, 29 Nov 2007 02:16:40 -0500, Gilles G. wrote:
> (... start a new thread because I just don't know who to reply to)
>
> Many posts about const/invariant talk about the "problem" of defining
> const functions. Some think we should indicate constness at the end of
> the function declaration, but it is also possible to do it at the front.
> So, as far as I understand it, there are two ways to express function
> constness for now:
> const int foo();
> int foo() const;
> To my mind, both solutions are unintuitive. I would expect something
> like that:
> int const foo();
> Is there any big argument against this?
I agree. A definition like:
const T foo();
looks to me like the returned T is const, and putting the const after the function is way too non-D for me, so all that is left that makes sense is:
T const foo();
|
December 04, 2007 Re: Const function (humble request) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Graham St Jack | I see I am not the only who don't understand why const function written like this:
T const myFunction()
was not envisaged.
Could anyone explain why?
Thanks in advance!
--
Gilles
Graham St Jack Wrote:
> On Thu, 29 Nov 2007 02:16:40 -0500, Gilles G. wrote:
>
> > (... start a new thread because I just don't know who to reply to)
> >
> > Many posts about const/invariant talk about the "problem" of defining
> > const functions. Some think we should indicate constness at the end of
> > the function declaration, but it is also possible to do it at the front.
> > So, as far as I understand it, there are two ways to express function
> > constness for now:
> > const int foo();
> > int foo() const;
> > To my mind, both solutions are unintuitive. I would expect something
> > like that:
> > int const foo();
> > Is there any big argument against this?
>
> I agree. A definition like:
>
> const T foo();
>
> looks to me like the returned T is const, and putting the const after the function is way too non-D for me, so all that is left that makes sense is:
>
> T const foo();
|
Copyright © 1999-2021 by the D Language Foundation