mirror of
https://github.com/boostorg/type_traits.git
synced 2025-07-30 04:27:22 +02:00
Document new traits classes.
This commit is contained in:
@ -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]
|
||||
|
||||
|
40
doc/is_assignable.qbk
Normal file
40
doc/is_assignable.qbk
Normal file
@ -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 <class T, class U>
|
||||
struct is_assignable : public __tof {};
|
||||
|
||||
__inherit If `std::declval<T>() = std::declval<U>()` 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<int, int>::value
|
||||
|
||||
is `false` since `std::declval<int>()` 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<T&, const U&>::value
|
||||
|
||||
If you're intention is to check for move-assignment then use:
|
||||
|
||||
is_assignable<T&, U&&>::value
|
||||
|
||||
or simply:
|
||||
|
||||
is_assignable<T&, U>::value
|
||||
|
||||
|
||||
__compat Requires the C++11 features `decltype` and SFINAE-expressions for full support.
|
||||
|
||||
__header ` #include <boost/type_traits/is_assignable.hpp>` or ` #include <boost/type_traits.hpp>`
|
||||
|
||||
[endsect]
|
||||
|
44
doc/is_constructible.qbk
Normal file
44
doc/is_constructible.qbk
Normal file
@ -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 <class T, class... Args>
|
||||
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<Args>()...);
|
||||
|
||||
valid?
|
||||
|
||||
There are a number of important special cases for this trait:
|
||||
|
||||
is_constructible<T>::value
|
||||
|
||||
Indicates whether `T` is default constructible, while:
|
||||
|
||||
is_constructible<T, const T&>::value
|
||||
|
||||
Indicates whether `T` is copy-constructible, and:
|
||||
|
||||
is_constructible<T, T>::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 <boost/type_traits/is_copy_constructible.hpp>` or ` #include <boost/type_traits.hpp>`
|
||||
|
||||
[endsect]
|
||||
|
23
doc/is_default_constructible.qbk
Normal file
23
doc/is_default_constructible.qbk
Normal file
@ -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 <class T>
|
||||
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 <boost/type_traits/is_copy_constructible.hpp>` or ` #include <boost/type_traits.hpp>`
|
||||
|
||||
[endsect]
|
||||
|
23
doc/is_destructible.qbk
Normal file
23
doc/is_destructible.qbk
Normal file
@ -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 <class T>
|
||||
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 <boost/type_traits/is_copy_constructible.hpp>` or ` #include <boost/type_traits.hpp>`
|
||||
|
||||
[endsect]
|
||||
|
@ -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]
|
||||
|
@ -153,12 +153,33 @@ The following templates describe the general properties of a type.
|
||||
template <class T>
|
||||
struct __is_abstract;
|
||||
|
||||
template <class T, class U>
|
||||
struct __is_assignable;
|
||||
|
||||
template <class T>
|
||||
struct __is_copy_constructible;
|
||||
|
||||
template <class T>
|
||||
struct __is_copy_assignable;
|
||||
|
||||
template <class T, class... Args>
|
||||
struct __is_constructible;
|
||||
|
||||
template <class T>
|
||||
struct __is_default_constructible;
|
||||
|
||||
template <class T>
|
||||
struct __is_destructible;
|
||||
|
||||
template <class T>
|
||||
struct __is_const;
|
||||
|
||||
template <class T>
|
||||
struct __is_empty;
|
||||
|
||||
template <class T>
|
||||
struct __is_final;
|
||||
|
||||
template <class T>
|
||||
struct __is_stateless;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#if !defined(BOOST_HAS_NOTHROW_ASSIGN) || defined(BOOST_MSVC) || defined(BOOST_INTEL)
|
||||
#include <boost/type_traits/has_trivial_assign.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <boost/type_traits/detail/decl.hpp>
|
||||
#include <boost/declval.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
@ -39,7 +39,7 @@ namespace boost {
|
||||
namespace detail
|
||||
{
|
||||
template <class T, bool b1, bool b2> struct has_nothrow_assign_imp{ static const bool value = false; };
|
||||
template <class T> struct has_nothrow_assign_imp<T, false, true>{ static const bool value = noexcept(detail::tt_decl_ref<T>() = detail::tt_decl_const_ref<T>()); };
|
||||
template <class T> struct has_nothrow_assign_imp<T, false, true>{ static const bool value = noexcept(boost::declval<typename add_reference<T>::type>() = boost::declval<typename add_reference<T const>::type>()); };
|
||||
template <class T, std::size_t N> struct has_nothrow_assign_imp<T[N], false, true>{ static const bool value = has_nothrow_assign_imp<T, false, true>::value; };
|
||||
template <class T> struct has_nothrow_assign_imp<T[], false, true>{ static const bool value = has_nothrow_assign_imp<T, false, true>::value; };
|
||||
}
|
||||
|
Reference in New Issue
Block a user