Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7684 > unrolled thread

mutable v's non const

Started by"Paul" <pchristor@yahoo.co.uk>
First post2011-07-09 18:15 +0100
Last post2011-07-15 00:50 -0500
Articles 20 on this page of 24 — 11 participants

Back to article view | Back to comp.lang.c++


Contents

  mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-09 18:15 +0100
    Re: mutable v's non const red floyd <no.spam.here@its.invalid> - 2011-07-09 21:26 -0700
      Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 09:58 +0100
        Re: mutable v's non const Ian Collins <ian-news@hotmail.com> - 2011-07-10 21:16 +1200
        Re: mutable v's non const Daniel Weber <usenet@daniel-weber.eu> - 2011-07-10 12:41 +0200
          Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-10 14:01 +0100
            Re: mutable v's non const Miles Bader <miles@gnu.org> - 2011-07-10 23:35 +0900
            Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 16:15 +0100
          Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 16:12 +0100
            Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 16:21 +0100
              Re: mutable v's non const Werner Erasmus <werasm@gmail.com> - 2011-07-10 21:55 +0200
                Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 21:45 +0100
                  Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-10 22:03 +0100
                    Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 23:37 +0100
                  Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-11 17:43 +0100
                    Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-11 17:48 +0100
                      Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-11 18:04 +0100
                        Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-11 18:14 +0100
                          Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-11 18:32 +0100
                            Re: mutable v's non const Oliver Jackson <chexmofo@hotmail.com> - 2011-07-12 12:32 -0700
                          Re: mutable v's non const "io_x" <a@b.c.invalid> - 2011-07-12 09:42 +0200
        Re: mutable v's non const Werner Erasmus <werasm@gmail.com> - 2011-07-10 17:17 +0200
        Re: mutable v's non const Juha Nieminen <nospam@thanks.invalid> - 2011-07-12 06:04 +0000
      Re: mutable v's non const "MikeP" <mp011011@some.org> - 2011-07-15 00:50 -0500

Page 1 of 2  [1] 2  Next page →


#7684 — mutable v's non const

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-09 18:15 +0100
Subjectmutable v's non const
Message-ID<A00Sp.5482$Zm3.103@newsfe11.ams2>
Hi groupies.

What is the meaning of the "mutable" word in C++  circles?
Mutable apparently means "it can change". So why are the terms "mutable" and 
"non-mutable" used instead of const and non-const and in what way are they 
different? 

[toc] | [next] | [standalone]


#7689

Fromred floyd <no.spam.here@its.invalid>
Date2011-07-09 21:26 -0700
Message-ID<ivb9mo$grv$1@dont-email.me>
In reply to#7684
On 7/9/2011 10:15 AM, Paul wrote:
> Hi groupies.
>
> What is the meaning of the "mutable" word in C++ circles?
> Mutable apparently means "it can change". So why are the terms "mutable"
> and "non-mutable" used instead of const and non-const and in what way
> are they different?

A mutable class member may be modified even if the object is const.

e.g.:

class Example {
    public:
       void good() const {
          mutable_int = 7;
       }
       void bad() const {
          non_mutable_int = 7; // ERROR
       }
       Example() :
         mutable_int(0), non_mutable_int(0)
       {
       }
   private:
      mutable int mutable_int;
      int non_mutable_int;
};

Example::good() will compile, and is fine.
Example::bad() will not compile because it's modifying a
   non-mutable member of a const object.

[toc] | [prev] | [next] | [standalone]


#7694

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-10 09:58 +0100
Message-ID<lRdSp.28808$Ll1.18268@newsfe24.ams2>
In reply to#7689
"red floyd" <no.spam.here@its.invalid> wrote in message 
news:ivb9mo$grv$1@dont-email.me...
> On 7/9/2011 10:15 AM, Paul wrote:
>> Hi groupies.
>>
>> What is the meaning of the "mutable" word in C++ circles?
>> Mutable apparently means "it can change". So why are the terms "mutable"
>> and "non-mutable" used instead of const and non-const and in what way
>> are they different?
>
> A mutable class member may be modified even if the object is const.
>
> e.g.:
>
> class Example {
>    public:
>       void good() const {
>          mutable_int = 7;
>       }
>       void bad() const {
>          non_mutable_int = 7; // ERROR
>       }
>       Example() :
>         mutable_int(0), non_mutable_int(0)
>       {
>       }
>   private:
>      mutable int mutable_int;
>      int non_mutable_int;
> };
>
Thanks for the example.

Why would you make such a function const in the first place?
If its not const why mark it as const?
> Example::good() will compile, and is fine.
> Example::bad() will not compile because it's modifying a
>   non-mutable member of a const object.
>
> 

[toc] | [prev] | [next] | [standalone]


#7695

FromIan Collins <ian-news@hotmail.com>
Date2011-07-10 21:16 +1200
Message-ID<97t90qFpbuU1@mid.individual.net>
In reply to#7694
On 07/10/11 08:58 PM, Paul wrote:
>
> "red floyd"<no.spam.here@its.invalid>  wrote in message
> news:ivb9mo$grv$1@dont-email.me...
>> On 7/9/2011 10:15 AM, Paul wrote:
>>> Hi groupies.
>>>
>>> What is the meaning of the "mutable" word in C++ circles?
>>> Mutable apparently means "it can change". So why are the terms "mutable"
>>> and "non-mutable" used instead of const and non-const and in what way
>>> are they different?
>>
>> A mutable class member may be modified even if the object is const.
>>
>> e.g.:
>>
>> class Example {
>>     public:
>>        void good() const {
>>           mutable_int = 7;
>>        }
>>        void bad() const {
>>           non_mutable_int = 7; // ERROR
>>        }
>>        Example() :
>>          mutable_int(0), non_mutable_int(0)
>>        {
>>        }
>>    private:
>>       mutable int mutable_int;
>>       int non_mutable_int;
>> };
>>
> Thanks for the example.
>
> Why would you make such a function const in the first place?
> If its not const why mark it as const?

So it can be called on a const instance of an Example.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#7697

FromDaniel Weber <usenet@daniel-weber.eu>
Date2011-07-10 12:41 +0200
Message-ID<ivbvl5$oj2$1@weretis.net>
In reply to#7694
Am 10.07.2011 10:58, schrieb Paul:
> Why would you make such a function const in the first place?
> If its not const why mark it as const?

Consider the difference between technically const and semantically const.

You might e.g. have a class (the program's configuration settings) which 
needs to synchronize parallel calls to some/all methods and therefore 
has a helper attribute which is used for the synchronization. When one 
of the synchronized method is semantically const - it doesn't change any 
of the configuration settings - but it has to change the helper attribute...

Bye,
	Daniel

[toc] | [prev] | [next] | [standalone]


#7700

FromLeigh Johnston <leigh@i42.co.uk>
Date2011-07-10 14:01 +0100
Message-ID<TaSdnTzScqgvP4TTnZ2dnUVZ8iudnZ2d@giganews.com>
In reply to#7697
On 10/07/2011 11:41, Daniel Weber wrote:
> Am 10.07.2011 10:58, schrieb Paul:
>> Why would you make such a function const in the first place?
>> If its not const why mark it as const?
>
> Consider the difference between technically const and semantically const.

I think the terms "logically const" and "physically const" are more 
cromulent.

[snip]

/Leigh

[toc] | [prev] | [next] | [standalone]


#7701

FromMiles Bader <miles@gnu.org>
Date2011-07-10 23:35 +0900
Message-ID<87r55ytd8n.fsf@catnip.gol.com>
In reply to#7700
Leigh Johnston <leigh@i42.co.uk> writes:
>> Consider the difference between technically const and semantically const.
>
> I think the terms "logically const" and "physically const" are more
> cromulent.

"consty" ?

-miles

-- 
We live, as we dream -- alone....

[toc] | [prev] | [next] | [standalone]


#7703

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-10 16:15 +0100
Message-ID<TmjSp.6954$UX1.5142@newsfe10.ams2>
In reply to#7700
"Leigh Johnston" <leigh@i42.co.uk> wrote in message 
news:TaSdnTzScqgvP4TTnZ2dnUVZ8iudnZ2d@giganews.com...
> On 10/07/2011 11:41, Daniel Weber wrote:
>> Am 10.07.2011 10:58, schrieb Paul:
>>> Why would you make such a function const in the first place?
>>> If its not const why mark it as const?
>>
>> Consider the difference between technically const and semantically const.
>
> I think the terms "logically const" and "physically const" are more 
> cromulent.
>
Daniels terms seem more fitting to me. I did see the term "logically 
constant" in one of the articles I read to be fair to you. 

[toc] | [prev] | [next] | [standalone]


#7702

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-10 16:12 +0100
Message-ID<OjjSp.1595$Z04.630@newsfe07.ams2>
In reply to#7697
"Daniel Weber" <usenet@daniel-weber.eu> wrote in message 
news:ivbvl5$oj2$1@weretis.net...
> Am 10.07.2011 10:58, schrieb Paul:
>> Why would you make such a function const in the first place?
>> If its not const why mark it as const?
>
> Consider the difference between technically const and semantically const.
>
> You might e.g. have a class (the program's configuration settings) which 
> needs to synchronize parallel calls to some/all methods and therefore has 
> a helper attribute which is used for the synchronization. When one of the 
> synchronized method is semantically const - it doesn't change any of the 
> configuration settings - but it has to change the helper attribute...
>
It seems to be a bit of a cheat to allow a modifiable data member of a const 
object.
I did a little research , it seems to be a case that this only applies to 
non static members. Handy for debugging according to the first couple of 
pages I read about it.

After further thinking about your explanation about a helper attribute it 
seems pretty much spot on.

[toc] | [prev] | [next] | [standalone]


#7705

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-10 16:21 +0100
Message-ID<isjSp.20204$29.13258@newsfe08.ams2>
In reply to#7702
"Paul" <pchristor@yahoo.co.uk> wrote in message 
news:OjjSp.1595$Z04.630@newsfe07.ams2...
>
> "Daniel Weber" <usenet@daniel-weber.eu> wrote in message 
> news:ivbvl5$oj2$1@weretis.net...
>> Am 10.07.2011 10:58, schrieb Paul:
>>> Why would you make such a function const in the first place?
>>> If its not const why mark it as const?
>>
>> Consider the difference between technically const and semantically const.
>>
>> You might e.g. have a class (the program's configuration settings) which 
>> needs to synchronize parallel calls to some/all methods and therefore has 
>> a helper attribute which is used for the synchronization. When one of the 
>> synchronized method is semantically const - it doesn't change any of the 
>> configuration settings - but it has to change the helper attribute...
>>
> It seems to be a bit of a cheat to allow a modifiable data member of a 
> const object.
> I did a little research , it seems to be a case that this only applies to 
> non static members.

Maybe I am incorrect about this only being applicable to nonstaic data 
members. Can anyone clarify if the mutable qualifier can be used on objects 
other than nonstatic class members? 

[toc] | [prev] | [next] | [standalone]


#7706

FromWerner Erasmus <werasm@gmail.com>
Date2011-07-10 21:55 +0200
Message-ID<_qKdnS8NssJYnofTnZ2dnUVZ7q-dnZ2d@saix.net>
In reply to#7705
Paul wrote:

> Maybe I am incorrect about this only being applicable to nonstaic data
> members. Can anyone clarify if the mutable qualifier can be used on
> objects other than nonstatic class members?

What would be the point of making them applicable to static
class members? The keyword mutable only makes sense during
the execution of const (member) functions. Par 7.1.1:10 (n3242)
makes it clear that mutable only applies to names of class data
members, and not to members declared const or static. 7.1.1:11
elaborates on its precise purpose.

Kind regards,

Werner

[toc] | [prev] | [next] | [standalone]


#7708

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-10 21:45 +0100
Message-ID<hcoSp.17567$yn7.1316@newsfe20.ams2>
In reply to#7706
"Werner Erasmus" <werasm@gmail.com> wrote in message 
news:_qKdnS8NssJYnofTnZ2dnUVZ7q-dnZ2d@saix.net...
> Paul wrote:
>
>> Maybe I am incorrect about this only being applicable to nonstaic data
>> members. Can anyone clarify if the mutable qualifier can be used on
>> objects other than nonstatic class members?
>
> What would be the point of making them applicable to static
> class members? The keyword mutable only makes sense during
> the execution of const (member) functions. Par 7.1.1:10 (n3242)
> makes it clear that mutable only applies to names of class data
> members, and not to members declared const or static. 7.1.1:11
> elaborates on its precise purpose.
>

I guess I was just wondering if this sort of thing was possible:

struct X{ const int i;}
mutable X anX;
anX.i =5;

[toc] | [prev] | [next] | [standalone]


#7709

FromLeigh Johnston <leigh@i42.co.uk>
Date2011-07-10 22:03 +0100
Message-ID<U8WdnduGcYAMjofTnZ2dnUVZ8gadnZ2d@giganews.com>
In reply to#7708
On 10/07/2011 21:45, Paul wrote:
>
> "Werner Erasmus" <werasm@gmail.com> wrote in message
> news:_qKdnS8NssJYnofTnZ2dnUVZ7q-dnZ2d@saix.net...
>> Paul wrote:
>>
>>> Maybe I am incorrect about this only being applicable to nonstaic data
>>> members. Can anyone clarify if the mutable qualifier can be used on
>>> objects other than nonstatic class members?
>>
>> What would be the point of making them applicable to static
>> class members? The keyword mutable only makes sense during
>> the execution of const (member) functions. Par 7.1.1:10 (n3242)
>> makes it clear that mutable only applies to names of class data
>> members, and not to members declared const or static. 7.1.1:11
>> elaborates on its precise purpose.
>>
>
> I guess I was just wondering if this sort of thing was possible:
>
> struct X{ const int i;}
> mutable X anX;
> anX.i =5;

FFS: TIAS; or to put it another way stop wasting bandwidth (and people's 
time) on Usenet.

Try reading a decent book or two rather than stumbling around in the dark.

/Leigh

[toc] | [prev] | [next] | [standalone]


#7711

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-10 23:37 +0100
Message-ID<XQpSp.12251$V25.10105@newsfe21.ams2>
In reply to#7709
"Leigh Johnston" <leigh@i42.co.uk> wrote in message 
news:U8WdnduGcYAMjofTnZ2dnUVZ8gadnZ2d@giganews.com...
> On 10/07/2011 21:45, Paul wrote:
>>
>> "Werner Erasmus" <werasm@gmail.com> wrote in message
>> news:_qKdnS8NssJYnofTnZ2dnUVZ7q-dnZ2d@saix.net...
>>> Paul wrote:
>>>
>>>> Maybe I am incorrect about this only being applicable to nonstaic data
>>>> members. Can anyone clarify if the mutable qualifier can be used on
>>>> objects other than nonstatic class members?
>>>
>>> What would be the point of making them applicable to static
>>> class members? The keyword mutable only makes sense during
>>> the execution of const (member) functions. Par 7.1.1:10 (n3242)
>>> makes it clear that mutable only applies to names of class data
>>> members, and not to members declared const or static. 7.1.1:11
>>> elaborates on its precise purpose.
>>>
>>
>> I guess I was just wondering if this sort of thing was possible:
>>
>> struct X{ const int i;}
>> mutable X anX;
>> anX.i =5;
>
> FFS: TIAS; or to put it another way stop wasting bandwidth (and people's 
> time) on Usenet.
>
If you think it's a waste of bandwidth then why add to the bandwidth wastage 
with your plop? 

[toc] | [prev] | [next] | [standalone]


#7730

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-11 17:43 +0100
Message-ID<hLFSp.2103$Z04.1601@newsfe07.ams2>
In reply to#7708
"Paul" <pchristor@yahoo.co.uk> wrote in message 
news:hcoSp.17567$yn7.1316@newsfe20.ams2...
>
> "Werner Erasmus" <werasm@gmail.com> wrote in message 
> news:_qKdnS8NssJYnofTnZ2dnUVZ7q-dnZ2d@saix.net...
>> Paul wrote:
>>
>>> Maybe I am incorrect about this only being applicable to nonstaic data
>>> members. Can anyone clarify if the mutable qualifier can be used on
>>> objects other than nonstatic class members?
>>
>> What would be the point of making them applicable to static
>> class members? The keyword mutable only makes sense during
>> the execution of const (member) functions. Par 7.1.1:10 (n3242)
>> makes it clear that mutable only applies to names of class data
>> members, and not to members declared const or static. 7.1.1:11
>> elaborates on its precise purpose.
>>
>
> I guess I was just wondering if this sort of thing was possible:
>
> struct X{ const int i;}
> mutable X anX;
> anX.i =5;
>
....or if there were any situations where mutable could be applied other 
than a nonstatic data member.

Please ignore Leighs rude comments as he has a tendancy to be nasty 
especially when he bears a grudge or three ;-)

Anyway thanks for posting of the quote from the standard as that seems to 
comfirm my original assumption.

[toc] | [prev] | [next] | [standalone]


#7731

FromLeigh Johnston <leigh@i42.co.uk>
Date2011-07-11 17:48 +0100
Message-ID<rsCdnYXoD8LLtIbTnZ2dnUVZ8nCdnZ2d@giganews.com>
In reply to#7730
On 11/07/2011 17:43, Paul wrote:
[snip]

>
> Please ignore Leighs rude comments as he has a tendancy to be nasty
> especially when he bears a grudge or three ;-)
>

No grudges; you're just an arsehole.

/Leigh

[toc] | [prev] | [next] | [standalone]


#7732

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-11 18:04 +0100
Message-ID<G2GSp.297$2I6.244@newsfe27.ams2>
In reply to#7731
"Leigh Johnston" <leigh@i42.co.uk> wrote in message 
news:rsCdnYXoD8LLtIbTnZ2dnUVZ8nCdnZ2d@giganews.com...
> On 11/07/2011 17:43, Paul wrote:
> [snip]
>
>>
>> Please ignore Leighs rude comments as he has a tendancy to be nasty
>> especially when he bears a grudge or three ;-)
>>
>
> No grudges; you're just an arsehole.
>
And what have I done to you to deserve that?
All I have done is prove you wrong about things on a few occasions for which 
you seem to bear a grudge. <shrug> 

[toc] | [prev] | [next] | [standalone]


#7734

FromLeigh Johnston <leigh@i42.co.uk>
Date2011-07-11 18:14 +0100
Message-ID<xOOdnVMm_bMcsobTnZ2dnUVZ8vOdnZ2d@giganews.com>
In reply to#7732
On 11/07/2011 18:04, Paul wrote:
>
> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
> news:rsCdnYXoD8LLtIbTnZ2dnUVZ8nCdnZ2d@giganews.com...
>> On 11/07/2011 17:43, Paul wrote:
>> [snip]
>>
>>>
>>> Please ignore Leighs rude comments as he has a tendancy to be nasty
>>> especially when he bears a grudge or three ;-)
>>>
>>
>> No grudges; you're just an arsehole.
>>
> And what have I done to you to deserve that?
> All I have done is prove you wrong about things on a few occasions for
> which you seem to bear a grudge. <shrug>

You are an arsehole because, for example, you constantly claim to have 
proven others wrong when you haven't (just like you did just now).  You 
are also actively homophobic which also counts towards you being an 
arsehole.  You are also an arsehole because you are unable to take 
criticism, admit to gaps in your knowledge and apologize for your mistakes.

HTH.

/Leigh

[toc] | [prev] | [next] | [standalone]


#7735

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-11 18:32 +0100
Message-ID<itGSp.27116$NX1.10918@newsfe18.ams2>
In reply to#7734
"Leigh Johnston" <leigh@i42.co.uk> wrote in message 
news:xOOdnVMm_bMcsobTnZ2dnUVZ8vOdnZ2d@giganews.com...
> On 11/07/2011 18:04, Paul wrote:
>>
>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>> news:rsCdnYXoD8LLtIbTnZ2dnUVZ8nCdnZ2d@giganews.com...
>>> On 11/07/2011 17:43, Paul wrote:
>>> [snip]
>>>
>>>>
>>>> Please ignore Leighs rude comments as he has a tendancy to be nasty
>>>> especially when he bears a grudge or three ;-)
>>>>
>>>
>>> No grudges; you're just an arsehole.
>>>
>> And what have I done to you to deserve that?
>> All I have done is prove you wrong about things on a few occasions for
>> which you seem to bear a grudge. <shrug>
>
> You are an arsehole because, for example, you constantly claim to have 
> proven others wrong when you haven't (just like you did just now).
I have proved you wrong on many occassions , you just do not accept it.

>  You are also actively homophobic which also counts towards you being an 
> arsehole.
:-S
WTF does homophobia have to do with anything and so what if I was 
homophobic. I'd rather be homophobic than homosexual.



>  You are also an arsehole because you are unable to take criticism, admit 
> to gaps in your knowledge and apologize for your mistakes.
>

Not at all. That's more like a description of yourself. 

[toc] | [prev] | [next] | [standalone]


#7755

FromOliver Jackson <chexmofo@hotmail.com>
Date2011-07-12 12:32 -0700
Message-ID<cefaf72f-8432-4356-ae0a-3c29036697a4@q12g2000prb.googlegroups.com>
In reply to#7735
On Jul 11, 10:32 am, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Leigh Johnston" <le...@i42.co.uk> wrote in message
>
> news:xOOdnVMm_bMcsobTnZ2dnUVZ8vOdnZ2d@giganews.com...
>
>
>
> > On 11/07/2011 18:04, Paul wrote:
>
> >> "Leigh Johnston" <le...@i42.co.uk> wrote in message
> >>news:rsCdnYXoD8LLtIbTnZ2dnUVZ8nCdnZ2d@giganews.com...
> >>> On 11/07/2011 17:43, Paul wrote:
> >>> [snip]
>
> >>>> Please ignore Leighs rude comments as he has a tendancy to be nasty
> >>>> especially when he bears a grudge or three ;-)
>
> >>> No grudges; you're just an arsehole.
>
> >> And what have I done to you to deserve that?
> >> All I have done is prove you wrong about things on a few occasions for
> >> which you seem to bear a grudge. <shrug>
>
> > You are an arsehole because, for example, you constantly claim to have
> > proven others wrong when you haven't (just like you did just now).
>
> I have proved you wrong on many occassions , you just do not accept it.
>
> >  You are also actively homophobic which also counts towards you being an
> > arsehole.
>
> :-S
> WTF does homophobia have to do with anything and so what if I was
> homophobic. I'd rather be homophobic than homosexual.

Paul, please post only when you have something on-topic to contribute.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c++


csiph-web