Apologies if I sent out an earlier version of this email already; our
NFS server is going nuts today...

On Thu, 16 Jun 2011, John Peterson wrote:

> We've stuck with the std::fill method for std::complex for now... I
> think in 99% of implementations memset should work there too, but I'm
> not sure if the standard guarantees std::complex has to look
> essentially like
>
> struct
> {
> T real;
> T imag;
> };
>
> i.e. still a POD?

That's a good question... I'd like to know too but haven't found the
full answer.  Looks like std::complex<T> for a standard-layout class T
is guaranteed to also be standard-layout...  but I'm not sure if
that's C++2003 or C++0x.

For C++2003 I can't find anything that precludes padding in
std::complex<T>, but there's no reason it'd be padded any differently
than your above struct (i.e. with float/double/long double, it won't
be).  Even with padding, though, memset could work if we just use
sizeof(Number) rather than 2*sizeof(Real)

There's a specification in C++0x that std::complex stuff be
reinterpret_cast'able to a length-2 array-of-T.  Technically that's not
a required assumption on C++2003 compilers, but "works in practice on
every current compiler and works as per standard on every future
compiler" is good enough for me.

>From a practical standpoint, in libMesh, we're already going to break
if this assumption is violated: check out the newest parallel.h.
libMesh::Parallel::StandardType<std::complex<T> > already assumes that
the data layout is the same as a length-2 array-of-T.

Quick summary: as long as we don't typedef Real into anything that
requires a deep copy (variable-precision classes?) both the memset
and the Parallel:: stuff should be fine.  If we do want to support
more tricky Reals, I'd suggest having a ZeroOutArray<T> functor class
that can be specialized.
---
Roy

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Libmesh-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-devel

Reply via email to