detected.qbk 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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:detected detected]
  9. template<template<class...> class Op, class... Args>
  10. using detected_t = __below;
  11. __alias `Op<Args...>` if it is a valid template-id, otherwise
  12. `boost::nonesuch`.
  13. __std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
  14. __compat Requires C++11 variadic templates and C++11 template aliases.
  15. __header `#include <boost/type_traits/detected.hpp>`
  16. __examples
  17. Suppose you wish to determine whether a type has a `size()` const-member function, then given the meta-functions:
  18. template <class T>
  19. using size_member_tester = decltype(std::declval<const T&>().size());
  20. template <class T>
  21. using size_member_t = boost::detected_t<size_member_tester, T >;
  22. Then the type `size_member_t<T>` is an alias for `size_member_tester<T>` if the operation is valid, and an alias for
  23. `boost::nonesuch` otherwise.
  24. See also: __is_detected, __is_detected_convertible, __is_detected_exact.
  25. [endsect]