Domenic Ippolito on Thu, 6 May 2004 01:44:08 -0500 (CDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [ALACPP] const char* NULL to std::string api


I think I would test for NULL, if it was really neccessary, just because of
the lower overhead.  But I agree with Chris that the *point* of passing by
reference instead of by pointer is to have the compiler do the null check
for you.

--Domenic

> This would seem like correct behavior to me. Contractually,
> "const std::string&" doesn't allow for a null value to be passed, and
> logic_error is about the kind of exception I'd expect from that
> scenario. This is the kind of thing that I *like* about the "modern"
> interface, as it avoids me having to write special case code for null
> string pointers.
>
> If you are hell bent on supporting the old behavior. I'd be tempted to
> do something like this:
>
> //Silly doFoo() guard that swallows the exception
> //We could just test for null here, but I'm annoyed
> //by the thought of doing it on top of the check
> //done int the STL
> inline void doFoo(const char* param) {
>     try {
> doFoo(param);
>     } catch (std::logic_error&) {
>         //nothing, because for some silly reason we think
> //this is okay behavior
>     }
> }
>
> void doFoo(const std::string& param);
>
> > The best I've come up with so far is some nasty boost::preprocessor
macro to write the parellel implementation for you. Does anybody have a
better idea?
>
> If null really *is* a valid value, then really the interface should be:
>
> void doFoo(const std::string* param);
>
> That will of course mean that all the callers will have to be changed,
> but it'd be the right thing to do.
>
> -- 
> Christopher Smith <x@xxxxxxxx>
> _______________________________________________
> alacpp mailing list
> alacpp@xxxxxxxxxxx
> http://lists.ellipsis.cx/mailman/listinfo/alacpp

_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp