Boost logo

Boost :

Subject: Re: [boost] [type_traits] Testing for copy constructor
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2015-04-19 01:46:49


On Sat, Apr 18, 2015 at 10:16 PM, Edward Diener <eldiener_at_[hidden]>
wrote:

> 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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk