- To: "'Jonathan Wakely'" <jwakely.gcc@xxxxxxxxx>
- Subject: RE: has_trivial_destructor improvable?
- From: "Hite, Christopher" <Christopher.Hite@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 22 Feb 2012 19:24:19 +0100
- Cc: "gcc-help@xxxxxxxxxxx" <gcc-help@xxxxxxxxxxx>
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1330539910; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:From:To:CC:Date:Subject: Message-ID:References:In-Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=Ho42d+8UtNeRsfXU9zUlMkiJUNk=; b=NDSK8UZfUTihxSD lbVz5HPD/KG1Y7OxD/93fLjd6Dk9YvUwmCJUdGPZMKSgtJbKayHl+3KKCiYBwbxs 4nOB0s/Fsxw8Q2hksyvyouGJwH45ZlR5ZicmJcwrk72J/OUX3ZnlvEyawPukVjDG 8g3pEs98k76nYWGXd5s3LTVzSqfc=
- In-reply-to: <CAH6eHdRc2mNMins38NrLU+eQ0WTPEEE35UmNeXa_2er78CE3gQ@mail.gmail.com>
> > Note that I'm using the class to avoid construction/deconstruction of an object:
> >
> > placeholder<std::string> ps;
> > std::string s("hi");
> > new(&ps.v) std::string(s);
> Instead of a union containing the template parameter type, how about using std::aligned_storage of suitable size instead?
Well that's the current impl (from boost optional.hpp)
union dummy_u
{
char data[ sizeof(T) ];
BOOST_DEDUCED_TYPENAME type_with_alignment<
::boost::alignment_of<T>::value >::type aligner_;
} dummy_ ;
I was hoping we could use a new union to do this, because it'd be a little more elegant and also gdb will displays the contents correctly (assuming they're valid).
The whole point of N2544 was to allow you to do stuff like this. I can declare a deconstructor/constructor for the union which does nothing. Unfortunately has_trivial_destructor doesn't get it.
That's just my use case though. A more general question: can you detect do nothing/trivial constructors/destructors/assignment on any struct/union/class?
For example if std::pair<bool,char> defines a copy constructor or assignment does it have to lose the "trivial" property?
Is there some proof that doing these things are impossible?
Chris
PS thanks for the quick response I may be out for a while.
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]