[type_traits] Testing for copy constructor

Does one use has_trivial_copy or has_nothrow_copy to determine if a class has a copy constructor or not ? I am writing some code that can do different things depending on whether a particular class has a copy constructor or does not have a copy constructor. I do not really care whether the copy constructor is a compiler generated copy constructor or not.

On Sat, Apr 18, 2015 at 10:16 PM, Edward Diener
Does one use has_trivial_copy or has_nothrow_copy to determine if a class has a copy constructor or not ?
I am writing some code that can do different things depending on whether a particular class has a copy constructor or does not have a copy constructor. I do not really care whether the copy constructor is a compiler generated copy constructor or not.
If you want to detect only noexcept constructors, use has_nothrow_copy. If you want to detect if the copy constructor is trivial (C++ standard definition of trivial), then use that. If you just want to see if the type is copyable, use is_copy_constructible. I also believe the boost trivial copy constructor specification differs slightly from the standard trait, as the wording makes it sound as though the boost trait also detects if the type is copyable. The standard trait, I believe, only detects the triviality -- a type can be trivially copyable but still have a deleted copy constructor. -- -Matt Calabrese
participants (2)
-
Edward Diener
-
Matt Calabrese