Brian Silverman | 4a2409e | 2018-08-04 23:24:02 -0700 | [diff] [blame^] | 1 | [/ |
| 2 | Copyright 2018 Glen Joseph Fernandes |
| 3 | <glenjofe -at- gmail.com> |
| 4 | |
| 5 | Distributed under the Boost Software License, |
| 6 | Version 1.0. (See accompanying file LICENSE_1_0.txt |
| 7 | or copy at http://www.boost.org/LICENSE_1_0.txt). |
| 8 | ] |
| 9 | |
| 10 | [section:detected detected] |
| 11 | |
| 12 | template<template<class...> class Op, class... Args> |
| 13 | using detected_t = __below; |
| 14 | |
| 15 | __alias `Op<Args...>` if it is a valid template-id, otherwise |
| 16 | `boost::nonesuch`. |
| 17 | |
| 18 | __std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502] |
| 19 | |
| 20 | __compat Requires C++11 variadic templates and C++11 template aliases. |
| 21 | |
| 22 | __header `#include <boost/type_traits/detected.hpp>` |
| 23 | |
| 24 | __examples |
| 25 | |
| 26 | Suppose you wish to determine whether a type has a `size()` const-member function, then given the meta-functions: |
| 27 | |
| 28 | template <class T> |
| 29 | using size_member_tester = decltype(std::declval<const T&>().size()); |
| 30 | |
| 31 | template <class T> |
| 32 | using size_member_t = boost::detected_t<size_member_tester, T >; |
| 33 | |
| 34 | |
| 35 | Then the type `size_member_t<T>` is an alias for `size_member_tester<T>` if the operation is valid, and an alias for |
| 36 | `boost::nonesuch` otherwise. |
| 37 | |
| 38 | See also: __is_detected, __is_detected_convertible, __is_detected_exact. |
| 39 | |
| 40 | [endsect] |