Re: has_trivial_destructor improvable?

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

 



On 22 February 2012 16:23, Hite, Christopher wrote:
>
>> What do you mean "breaks has_trivial_constructor" ?
>> Do you just mean has_trivial_default_constructor::value is false?
> yes though I'd expect it to be true.

A user-provided special member function is not trivial, even if it's empty.

>> If you declare the constructor and destructor as defaulted then they will be trivial for placeholder<X> if they are trivial for X:
>>        placeholder() = default;
>>        ~placeholder () = default;

(Please show complete examples, it's much easier to understand your
question if you show the code you're referring to.)

> Doesn't work:
>
> new_placeholder.cpp: In function 'int main()':
> new_placeholder.cpp:12:27: error: use of deleted function 'placeholder<T>::placeholder() [with T = std::basic_string<char>]'
> new_placeholder.cpp:7:2: error: 'placeholder<T>::placeholder() [with T = std::basic_string<char>]' is implicitly deleted because the default definition would be ill-formed:
> new_placeholder.cpp:6:4: error: union member 'placeholder<std::basic_string<char> >::v' with non-trivial 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'

Ah yes, it will be trivial if X has a trivial default constructor, but
deleted if X has a non-trivial default constructor.

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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux