Topic: standardese
Author: Andrei Alexandrescu <andrewalex@hotmail.com>
Date: 1999/05/25 Raw View
Hello,
I'm implementing a string-like wrapper. It does not implement reference
counting.
My question is: do I have to implement the methods exactly as the
standard says? For instance, 21.3.5.3 para 5 and 6 say:
basic_string<charT,traits,Allocator>&
assign(const charT* s, size_type n);
Returns: assign(basic_string<charT,traits,Allocator>( s, n)).
Do I really have to implement the function in this way? I don't want to
make a temporary string.
Thanks,
Andrei
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
[ 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: James Kuyper <kuyper@wizard.net>
Date: 1999/05/25 Raw View
Andrei Alexandrescu wrote:
>
> Hello,
>
> I'm implementing a string-like wrapper. It does not implement reference
> counting.
>
> My question is: do I have to implement the methods exactly as the
> standard says? For instance, 21.3.5.3 para 5 and 6 say:
>
> basic_string<charT,traits,Allocator>&
> assign(const charT* s, size_type n);
> Returns: assign(basic_string<charT,traits,Allocator>( s, n)).
>
> Do I really have to implement the function in this way? I don't want to
> make a temporary string.
There are several ways in which the user-written code may be substituted
for standard library functions or classes, and when it does, it must
meet all of the required behavior of the functions or classes it
substitutes for. Cases where this is true are
replacement functions: operators new and delete
handler functions: using set_*()
Components supplied as template arguments to standard library
templates.
Specializing a standard library template with a declaration
dependent on a user-defined name of external linkage.
As far as I can tell, what you want to do doesn't fall into any of these
categories, so you're free to rearrange the interface as you please.
Secondly - the code provided in definitions of the standard library is
meant as an example; you can use any other code you want that has the
same effect, including, as a special case, rewriting it so the temporary
isn't needed.
[ 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: Gabriel Dos_Reis <gdosreis@korrigan.inria.fr>
Date: 1999/05/25 Raw View
Andrei Alexandrescu <andrewalex@hotmail.com> writes:
AA| Hello,
AA|
AA| I'm implementing a string-like wrapper. It does not implement reference
AA| counting.
AA|
AA| My question is: do I have to implement the methods exactly as the
AA| standard says? For instance, 21.3.5.3 para 5 and 6 say:
AA|
AA| basic_string<charT,traits,Allocator>&
AA| assign(const charT* s, size_type n);
AA| Returns: assign(basic_string<charT,traits,Allocator>( s, n)).
AA|
AA| Do I really have to implement the function in this way?
See the "as-if" rule.
--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
---
[ 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: dHarrison@worldnet.att.net (Doug Harrison)
Date: 1999/05/25 Raw View
Andrei Alexandrescu wrote:
>Hello,
>
>I'm implementing a string-like wrapper. It does not implement reference
>counting.
>
>My question is: do I have to implement the methods exactly as the
>standard says? For instance, 21.3.5.3 para 5 and 6 say:
>
>basic_string<charT,traits,Allocator>&
>assign(const charT* s, size_type n);
>Returns: assign(basic_string<charT,traits,Allocator>( s, n)).
>
>Do I really have to implement the function in this way? I don't want to
>make a temporary string.
No, you don't, but what you do write should behave as if it had done exactly
what the standard "prescribes", except for creation of temporaries. This
includes performing the error-checking that is implicit in the ctor calls.
Above, your assign function must check that n is not npos and throw
length_error if it is. Also, you must ensure that your optimized assign() is
as safe as the standard's version. When dealing with char_type* parameters,
this can mean checking for overlap with your string's internal
representation.
--
Doug Harrison
dHarrison@worldnet.att.net
[ 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 ]