is_convertible.qbk 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [/
  2. Copyright 2007 John Maddock.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:is_convertible is_convertible]
  8. template <class From, class To>
  9. struct is_convertible : public __tof {};
  10. __inherit If an imaginary rvalue of type `From` is convertible to type `To` then
  11. inherits from __true_type, otherwise inherits from __false_type.
  12. Type From must not be an incomplete type.
  13. Type To must not be an incomplete, or function type.
  14. No types are considered to be convertible to array types or abstract-class types.
  15. This template can not detect whether a converting-constructor is `public` or not: if
  16. type `To` has a `private` converting constructor from type `From` then instantiating
  17. `is_convertible<From, To>` will produce a compiler error. For this reason `is_convertible`
  18. can not be used to determine whether a type has a `public` copy-constructor or not.
  19. This template will also produce compiler errors if the conversion is ambiguous,
  20. for example:
  21. struct A {};
  22. struct B : A {};
  23. struct C : A {};
  24. struct D : B, C {};
  25. // This produces a compiler error, the conversion is ambiguous:
  26. bool const y = boost::is_convertible<D*,A*>::value;
  27. __std_ref 4 and 8.5.
  28. [all_compilers]
  29. __header ` #include <boost/type_traits/is_convertible.hpp>` or ` #include <boost/type_traits.hpp>`
  30. __examples
  31. [:`is_convertible<int, double>` inherits from `__true_type`.]
  32. [:`is_convertible<const int, double>::type` is the type `__true_type`.]
  33. [:`is_convertible<int* const, int*>::value` is an integral constant
  34. expression that evaluates to /true/.]
  35. [:`is_convertible<int const*, int*>::value` is an integral constant
  36. expression that evaluates to /false/: the conversion would require a `const_cast`.]
  37. [:`is_convertible<int const&, long>::value` is an integral constant
  38. expression that evaluates to /true/.]
  39. [:`is_convertible<int, int>::value` is an integral constant
  40. expression that evaluates to /true/.]
  41. [:`is_convertible<T, T>::value_type` is the type `bool`.]
  42. [endsect]