blob: b788af5dac43e487a610e9628aff0cea8796c85b [file] [log] [blame]
Brian Silverman4a2409e2018-08-04 23:24:02 -07001[/
2Copyright 2018 Glen Joseph Fernandes
3<glenjofe -at- gmail.com>
4
5Distributed under the Boost Software License,
6Version 1.0. (See accompanying file LICENSE_1_0.txt
7or copy at http://www.boost.org/LICENSE_1_0.txt).
8]
9
10[section:is_detected is_detected]
11
12 template<template<class...> class Op, class... Args>
13 using is_detected = __below;
14
15 template<template<class...> class Op, class... Args>
16 constexpr bool is_detected_v = is_detected<Op, Args...>::value;
17
18__alias If `Op<Args...>` is a valid template-id, aliases __true_type,
19otherwise aliases __false_type.
20
21__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
22
23__compat Requires C++11 variadic templates and C++11 template aliases.
24
25__header `#include <boost/type_traits/is_detected.hpp>`
26
27__examples
28
29Suppose we wish to "reset" a value of type T, if the type has a `clear()` member function then we should call
30it, otherwise we should assign a default constructed value:
31
32 template<class T>
33 using clear_t = decltype(boost::declval<T&>().clear());
34
35 template<class T>
36 void clear(T& value)
37 {
38 if constexpr (boost::is_detected_v<clear_t, T>) {
39 value.clear();
40 } else {
41 value = T();
42 }
43 }
44
45See also: __is_detected_convertible, __is_detected_exact.
46
47[endsect]