| [/ |
| Copyright 2018 Glen Joseph Fernandes |
| <glenjofe -at- gmail.com> |
| |
| Distributed under the Boost Software License, |
| Version 1.0. (See accompanying file LICENSE_1_0.txt |
| or copy at http://www.boost.org/LICENSE_1_0.txt). |
| ] |
| |
| [section:detected_or detected_or] |
| |
| template<class Default, template<class...> class Op, class... Args> |
| using detected_or = __below; |
| |
| template<class Default, template<class...> class Op, class... Args> |
| using detected_or_t = typename detected_or<Default, Op, Args...>::type; |
| |
| __alias An unspecified type with two public member type definitions: |
| |
| * `value_t` is __true_type if `Op<Args...>` is a valid template-id, otherwise |
| __false_type |
| * `type` is `Op<Args...>` if it is a valid template-id, otherwise `Default` |
| |
| __std_paper [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf N4502] |
| |
| __compat Requires C++11 variadic templates and C++11 template aliases. |
| |
| __header `#include <boost/type_traits/detected_or.hpp>` |
| |
| __examples |
| |
| Suppose we wish to declare a type that represents the difference between two values of type T, it should be |
| T::difference_type if such a type exists, or std::ptrdiff_t otherwise: |
| |
| template<class T> |
| using difference_t = typename T::difference_type; |
| |
| template<class T> |
| using difference_type = boost::detected_or_t<std::ptrdiff_t, difference_t, T>; |
| |
| Now the type `difference_type<T>` gives us what we need. |
| |
| See also: __is_detected, __is_detected_convertible, __is_detected_exact. |
| |
| [endsect] |