enable_if.qbk 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. [/
  2. Copyright 2018 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License,
  5. Version 1.0. (See accompanying file LICENSE_1_0.txt
  6. or copy at http://www.boost.org/LICENSE_1_0.txt).
  7. ]
  8. [section:enable_if enable_if_]
  9. template<bool B, class T = void>
  10. struct enable_if_;
  11. template<bool B, class T = void>
  12. using enable_if_t = typename enable_if_<B, T>::type;
  13. __type If `B` is true, then the member `type` is defined to be `T`. Otherwise
  14. there is no member `type`.
  15. __header `#include <boost/type_traits/enable_if.hpp>`
  16. [note The trait has the name `enable_if_` (with a trailing underscore) but
  17. behaves like `std::enable_if` or `boost::enable_if_c`. The existing trait
  18. with the name `boost::enable_if` has a different interface.]
  19. __examples
  20. The following function can be used to destroy each element of an array and
  21. specially handle arrays of trivially destructible types.
  22. template<class T>
  23. typename boost::enable_if_<!boost::has_trivial_destructor<T>::value>::type
  24. destroy(T* ptr, std::size_t size)
  25. {
  26. while (size > 0) {
  27. ptr[--size].~T();
  28. }
  29. }
  30. template<class T>
  31. typename boost::enable_if_<boost::has_trivial_destructor<T>::value>::type
  32. destroy(T*, std::size_t) { }
  33. [all_compilers] The type alias `enable_if_t` is only available if the compiler
  34. supports template aliases.
  35. [endsect]