From e68fddd99246c9bff4dc8198b0b4e21b7db4f93a Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 13 Jun 2015 19:19:22 +0100 Subject: [PATCH] Document new traits classes. --- doc/history.qbk | 2 + doc/is_assignable.qbk | 40 +++++++++++++++++ doc/is_constructible.qbk | 44 +++++++++++++++++++ doc/is_default_constructible.qbk | 23 ++++++++++ doc/is_destructible.qbk | 23 ++++++++++ doc/type_traits.qbk | 8 ++++ doc/value_traits.qbk | 21 +++++++++ .../boost/type_traits/has_nothrow_assign.hpp | 4 +- 8 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 doc/is_assignable.qbk create mode 100644 doc/is_constructible.qbk create mode 100644 doc/is_default_constructible.qbk create mode 100644 doc/is_destructible.qbk diff --git a/doc/history.qbk b/doc/history.qbk index 21b7011..45abeef 100644 --- a/doc/history.qbk +++ b/doc/history.qbk @@ -11,6 +11,8 @@ * Refactored traits to depend only on Boost.Config. Greatly simplified code to improve readability and remove workarounds for old compilers no longer supported. * Fix __decay to follow C++11 semantics, see [@https://svn.boost.org/trac/boost/ticket/7760 #7760]. +* Added a number of new traits __is_assignable, __is_default_constructible, __is_constructible and __is_destructible required to fix bugs in a number of other traits, +see for example [@https://svn.boost.org/trac/boost/ticket/7760 #11324]. [h4 Boost 1.58.0] diff --git a/doc/is_assignable.qbk b/doc/is_assignable.qbk new file mode 100644 index 0000000..fe4089e --- /dev/null +++ b/doc/is_assignable.qbk @@ -0,0 +1,40 @@ +[/ + Copyright 2015 John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + +[section:is_assignable is_assignable] + + template + struct is_assignable : public __tof {}; + +__inherit If `std::declval() = std::declval()` then inherits from __true_type, +otherwise from __flase_type. Type `T` must be a complete type. + +Note that this trait is somewhat tricky to use correctly: for example: + + is_assignable::value + +is `false` since `std::declval()` is an ['xvalue] which can not be assigned to! + +If you're intention is to check for copy-assignment from some type U then use: + + is_assignable::value + +If you're intention is to check for move-assignment then use: + + is_assignable::value + +or simply: + + is_assignable::value + + +__compat Requires the C++11 features `decltype` and SFINAE-expressions for full support. + +__header ` #include ` or ` #include ` + +[endsect] + diff --git a/doc/is_constructible.qbk b/doc/is_constructible.qbk new file mode 100644 index 0000000..b301a25 --- /dev/null +++ b/doc/is_constructible.qbk @@ -0,0 +1,44 @@ +[/ + Copyright 2015 John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + +[section:is_constructible is_constructible] + + template + struct is_constructible : public __tof {}; + +__inherit If `T` can be constructed from `Args`, +then inherits from __true_type, otherwise inherits from __false_type. Type `T` +must be a complete type. + +Formally the trait answers the question, is the expression: + + T t(std::declval()...); + +valid? + +There are a number of important special cases for this trait: + + is_constructible::value + +Indicates whether `T` is default constructible, while: + + is_constructible::value + +Indicates whether `T` is copy-constructible, and: + + is_constructible::value + +Indicates whether `T` is move-constructible. + + +__compat This trait requires the C++11 features `decltype` variadic templates and SFINAE-expression support for full support. +While there is some fallback code for cases where this is not the case, the trait should really be considered broken in that case. + +__header ` #include ` or ` #include ` + +[endsect] + diff --git a/doc/is_default_constructible.qbk b/doc/is_default_constructible.qbk new file mode 100644 index 0000000..94caf25 --- /dev/null +++ b/doc/is_default_constructible.qbk @@ -0,0 +1,23 @@ +[/ + Copyright 2015 John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + +[section:is_default_constructible is_default_constructible] + + template + struct is_default_constructible : public __tof {}; + +__inherit If `T` can be default-constructed +then inherits from __true_type, otherwise inherits from __false_type. Type `T` +must be a complete type. + +__compat This trait requires the C++11 feature `decltype` support for full support. +While there is some fallback code for cases where this is not the case, the trait should really be considered broken in that case. + +__header ` #include ` or ` #include ` + +[endsect] + diff --git a/doc/is_destructible.qbk b/doc/is_destructible.qbk new file mode 100644 index 0000000..335b245 --- /dev/null +++ b/doc/is_destructible.qbk @@ -0,0 +1,23 @@ +[/ + Copyright 2015 John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + +[section:is_destructible is_destructible] + + template + struct is_destructible : public __tof {}; + +__inherit If `T` does not have its destructor deleted +then inherits from __true_type, otherwise inherits from __false_type. Type `T` +must be a complete type. + +__compat This trait requires the C++11 features `decltype` and SFINAE-expression support for full support. +While there is some fallback code for cases where this is not the case, the trait should really be considered broken in that case. + +__header ` #include ` or ` #include ` + +[endsect] + diff --git a/doc/type_traits.qbk b/doc/type_traits.qbk index 9b0f68c..8a914a4 100644 --- a/doc/type_traits.qbk +++ b/doc/type_traits.qbk @@ -68,8 +68,12 @@ [def __extent [link boost_typetraits.reference.extent extent]] [def __is_empty [link boost_typetraits.reference.is_empty is_empty]] [def __is_const [link boost_typetraits.reference.is_const is_const]] +[def __is_assignable [link boost_typetraits.reference.is_assignable is_assignable]] [def __is_copy_constructible [link boost_typetraits.reference.is_copy_constructible is_copy_constructible]] [def __is_copy_assignable [link boost_typetraits.reference.is_copy_assignable is_copy_assignable]] +[def __is_constructible [link boost_typetraits.reference.is_constructible is_constructible]] +[def __is_default_constructible [link boost_typetraits.reference.is_default_constructible is_default_constructible]] +[def __is_destructible [link boost_typetraits.reference.is_destructible is_destructible]] [def __is_volatile [link boost_typetraits.reference.is_volatile is_volatile]] [def __is_abstract [link boost_typetraits.reference.is_abstract is_abstract]] [def __is_polymorphic [link boost_typetraits.reference.is_polymorphic is_polymorphic]] @@ -269,14 +273,18 @@ See __has_trivial_constructor. [include is_abstract.qbk] [include is_arithmetic.qbk] [include is_array.qbk] +[include is_assignable.qbk] [include is_base_of.qbk] [include is_class.qbk] [include is_complex.qbk] [include is_compound.qbk] [include is_const.qbk] +[include is_constructible.qbk] [include is_convertible.qbk] [include is_copy_assignable.qbk] [include is_copy_constructible.qbk] +[include is_default_constructible.qbk] +[include is_destructible.qbk] [include is_empty.qbk] [include is_enum.qbk] [include is_final.qbk] diff --git a/doc/value_traits.qbk b/doc/value_traits.qbk index c782cdd..5f667aa 100644 --- a/doc/value_traits.qbk +++ b/doc/value_traits.qbk @@ -153,12 +153,33 @@ The following templates describe the general properties of a type. template struct __is_abstract; + template + struct __is_assignable; + + template + struct __is_copy_constructible; + + template + struct __is_copy_assignable; + + template + struct __is_constructible; + + template + struct __is_default_constructible; + + template + struct __is_destructible; + template struct __is_const; template struct __is_empty; + template + struct __is_final; + template struct __is_stateless; diff --git a/include/boost/type_traits/has_nothrow_assign.hpp b/include/boost/type_traits/has_nothrow_assign.hpp index c864eef..0be0b2f 100644 --- a/include/boost/type_traits/has_nothrow_assign.hpp +++ b/include/boost/type_traits/has_nothrow_assign.hpp @@ -15,7 +15,7 @@ #if !defined(BOOST_HAS_NOTHROW_ASSIGN) || defined(BOOST_MSVC) || defined(BOOST_INTEL) #include #if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) -#include +#include #include #include #include @@ -39,7 +39,7 @@ namespace boost { namespace detail { template struct has_nothrow_assign_imp{ static const bool value = false; }; - template struct has_nothrow_assign_imp{ static const bool value = noexcept(detail::tt_decl_ref() = detail::tt_decl_const_ref()); }; + template struct has_nothrow_assign_imp{ static const bool value = noexcept(boost::declval::type>() = boost::declval::type>()); }; template struct has_nothrow_assign_imp{ static const bool value = has_nothrow_assign_imp::value; }; template struct has_nothrow_assign_imp{ static const bool value = has_nothrow_assign_imp::value; }; }