Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.


template <class T, class U>
struct is_assignable : public true_type-or-false_type {};

Inherits: If std::declval<T>() = std::declval<U>() then inherits from true_type, otherwise from false_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

Compiler Compatibility: 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>