Kay-Uwe Kasemir wrote:
On Sep 27, 2005, at 13:04 , Andrew Johnson wrote:
I agree that it's initially more convenient to be able to
use the operators.
But in the long run, it causes the C++ and e.g. Java sources
differ, and in C++ I also find it difficult to understand what's
called when everything has cast and assignment operators.
I am not providing cast operators, and to some extent I agree about the
difficulty reading code that uses them. However the assignment
operator= is an integral part of C++ that the compiler will create for
you (usually wrongly) if you don't explicitly tell it not to. I believe
it makes more sense to make use of the facilities provided by the
language than to try and suppress them, so I'm providing the convenience
operators. If you want your code to be easily translated into Java
you're not forced to use them to manipulate strings.
operator[] is not currently implemented in that fashion, but I am
willing to do that too (although I don't like your name so I will
probably change it).
class StringReader {
public:
...
// Individual byte access
virtual char at(size_t pos) const = 0;
...
// Overloaded operator, not virtual
char operator[] (size_t pos) const;
};
I'm now using the std::string name at() which will throw some kind of
out_of_range exception if pos points beyond the end of the string. The
inline overloaded operator[] is now just an inline synonym for at(),
which is different to std::string but safer - std::string::operator[]
does no checking of pos.
- Andrew
--
English probably arose from Normans trying to pick up Saxon girls.
- Replies:
- Re: strings Kay-Uwe Kasemir
- References:
- RE: data access structures, strings Jeff Hill
- Re: data access structures, strings Kay-Uwe Kasemir
- Re: data access structures, strings Andrew Johnson
- Re: data access structures, strings Kay-Uwe Kasemir
- Re: data access structures, strings Andrew Johnson
- Re: strings Kay-Uwe Kasemir
- Navigate by Date:
- Prev:
Re: EPICS Meeting agenda Marty Kraimer
- Next:
RE: EPICS Meeting agenda Jeff Hill
- Index:
2002
2003
2004
<2005>
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: strings Kay-Uwe Kasemir
- Next:
Re: strings Kay-Uwe Kasemir
- Index:
2002
2003
2004
<2005>
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|