🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #4008

mutable can be removed...

#4008
From: Igor Boukanov
Date: Fri, 12 Apr 1996 15:53
55 lines
2201 bytes
Subject: mutable can be removed...
Newsgroups: comp.std.c++
Organization: Fysisk institutt, Universitetet i Bergen
Summary: mutable semantic can be realized by template function.
Keywords: C++, mutable

Consider the following:

template<class T> T* remove_constness_from(const T* p)
{
   return const_cast<T*>(p);
}

So now instead of:

struct X { 
   mutable int i; 
   void set(int i_) const; 
};
void X::set(int i_) const { 
   i = i_; 
} 

one can wright:

struct X { 
   int i; 
   void set(int i_) const;
};
void X::set(int i_) const {
   remove_constness_from(this)->i = i_; 
} 
 
And remove_constness_from is more useful than mutable because in this 
case to make any class member looks like mutable one don't even need to 
modify class definition! And of cause lines like 
"remove_constness_from(this)->i = i_;"
will show explicitly what somebody does...

>From this point of view mutable keyword can be removed from C++. And it 
will not break any real code because as I now there is no compiler that 
can compile such code!
And of cause this will make C++ standard shorter...

--
Regards, Igor Boukanov. 
mailto:igor.boukanov@fi.uib.no  
http://www.fi.uib.no/~boukanov/
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <Pine.HPP.3.91.960412122220.29403A-100000@kvark.fi.uib.no>
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern
From: Igor Boukanov <Igor.Boukanov@fi.uib.no>
Newsgroups: comp.std.c++
Subject: mutable can be removed...
Date: 12 Apr 1996 08:53:37 PDT
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <Pine.HPP.3.91.960412122220.29403A-100000@kvark.fi.uib.no>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Fri, 12 Apr 1996 12:25:01 +0200 (METDST)
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMW58gUy4NqrwXLNJAQERagH6A+IAvxCnueDQoUmjWiUQU7WcQX1+QIgn
 4d3oCcO72PmA8wuh5TJwERWMjAhzWwu+g8tdzcS1jP5iIhhsfrURwg==
 =+fjG
Originator: austern@isolde.mti.sgi.com