This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: has_trivial_destructor improvable?


> > 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]