Topic: Const members in general (Was: Constness of hint in insert method)
Author: "Dave Abrahams" <abrahams@mediaone.net>
Date: 1999/07/01 Raw View
Valentin quoth imperiously:
>By the way do you think that the following should compile:
>=A0
>typedef const std::list<int> li;
>li c;
>li::iterator it =3D c.begin ();
>=A0
>[*hint* I understand the C++ language *hint*]
>=A0
>IMO this should compile fine.
>
>[*hint* Don't try to teach me C++ *hint*]
So, Valentin, are you proposing that there should be some kind of
specialization so that (const std::list<int>)::iterator is actually a
different type from (non-const)std::list<int>::iterator? If so, how do yo=
u
propose to accomplish that in c++?
If you have something in mind, don't just taunt us with it; spit it out,
man!
-Dave
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/07/01 Raw View
Dave Abrahams wrote:
>
> Valentin quoth imperiously:
>
> >By the way do you think that the following should compile:
> >
> >typedef const std::list<int> li;
> >li c;
> >li::iterator it = c.begin ();
> So, Valentin, are you proposing that there should be some kind of
> specialization so that (const std::list<int>)::iterator is actually a
> different type from (non-const)std::list<int>::iterator? If so, how do you
> propose to accomplish that in c++?
First, the point isn't to add yet another feature to
C++. If you don't think that the above code fragment
should compile, just tell me.
Otherwise, I would simply write:
class list {
public:
class iterator; // (1)
class const_iterator; // (2)
typedef const_iterator iterator const; // overloads (1)
};
list::iterator would be list::iterator (1)
const list::iterator would be list::const_iterator (2)
(Your use of specialisation is confusing because
this has nothing to do with template specialisation.)
--
Valentin Bonnard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/06/25 Raw View
By the way do you think that the following should compile:
typedef const std::list<int> li;
li c;
li::iterator it = c.begin ();
[*hint* I understand the C++ language *hint*]
IMO this should compile fine.
[*hint* Don't try to teach me C++ *hint*]
--
Valentin Bonnard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]