[Development] Improving toInt, toLong, etc.

Thiago Macieira thiago.macieira at intel.com
Wed Feb 5 22:16:53 CET 2014


Em qua 05 fev 2014, às 14:28:36, Matthew Woehlke escreveu:
> > You will just have an undefined behaviour.  You will return the content of
> > the uninitialized memory cast to the type, and it will likely cause a
> > crash later. Debug build will abort,  release build will probably crash
> > somehow too. Same as QList::at()
> > 
> > // possible implementation
> > T &QOptional<T>::operator*() {
> > 
> >     Q_ASSERT(isValid());
> >     return reinterpret_cast<T&>(data);
> > 
> > };
> 
> Right. I don't see why this seems to be a problem here, but is not for
> e.g. an invalid iterator, or at() / operator[] on a container with an
> invalid index. Just do what those do.

Fair enough. I hadn't thought of the solution Olivier gave, to be honest.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list