is_detected.qbk 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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:is_detected is_detected]
  9. template<template<class...> class Op, class... Args>
  10. using is_detected = __below;
  11. template<template<class...> class Op, class... Args>
  12. constexpr bool is_detected_v = is_detected<Op, Args...>::value;
  13. __alias If `Op<Args...>` is a valid template-id, aliases __true_type,
  14. otherwise aliases __false_type.
  15. __std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
  16. __compat Requires C++11 variadic templates and C++11 template aliases.
  17. __header `#include <boost/type_traits/is_detected.hpp>`
  18. __examples
  19. Suppose we wish to "reset" a value of type T, if the type has a `clear()` member function then we should call
  20. it, otherwise we should assign a default constructed value:
  21. template<class T>
  22. using clear_t = decltype(boost::declval<T&>().clear());
  23. template<class T>
  24. void clear(T& value)
  25. {
  26. if constexpr (boost::is_detected_v<clear_t, T>) {
  27. value.clear();
  28. } else {
  29. value = T();
  30. }
  31. }
  32. See also: __is_detected_convertible, __is_detected_exact.
  33. [endsect]