blob: e036fd04d6c7e5e4ba4e373415e738c7280a8426 [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:detected_or detected_or]
11
12 template<class Default, template<class...> class Op, class... Args>
13 using detected_or = __below;
14
15 template<class Default, template<class...> class Op, class... Args>
16 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
17
18__alias An unspecified type with two public member type definitions:
19
20* `value_t` is __true_type if `Op<Args...>` is a valid template-id, otherwise
21 __false_type
22* `type` is `Op<Args...>` if it is a valid template-id, otherwise `Default`
23
24__std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502]
25
26__compat Requires C++11 variadic templates and C++11 template aliases.
27
28__header `#include <boost/type_traits/detected_or.hpp>`
29
30__examples
31
32Suppose we wish to declare a type that represents the difference between two values of type T, it should be
33T::difference_type if such a type exists, or std::ptrdiff_t otherwise:
34
35 template<class T>
36 using difference_t = typename T::difference_type;
37
38 template<class T>
39 using difference_type = boost::detected_or_t<std::ptrdiff_t, difference_t, T>;
40
41Now the type `difference_type<T>` gives us what we need.
42
43See also: __is_detected, __is_detected_convertible, __is_detected_exact.
44
45[endsect]