| 1 |
// Copyright Matt Borland 2021. |
| 2 |
// Use, modification and distribution are subject to the |
| 3 |
// Boost Software License, Version 1.0. (See accompanying file |
| 4 |
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
// |
| 6 |
// https://en.cppreference.com/w/cpp/experimental/is_detected |
| 7 |
|
| 8 |
#ifndef BOOST_MATH_TOOLS_IS_DETECTED_HPP |
| 9 |
#define BOOST_MATH_TOOLS_IS_DETECTED_HPP |
| 10 |
|
| 11 |
#include <boost/math/tools/type_traits.hpp> |
| 12 |
|
| 13 |
namespace boost { namespace math { namespace tools { |
| 14 |
|
| 15 |
template <typename...> |
| 16 |
using void_t = void; |
| 17 |
|
| 18 |
namespace detail { |
| 19 |
|
| 20 |
template <typename Default, typename AlwaysVoid, template<typename...> class Op, typename... Args> |
| 21 |
struct detector |
| 22 |
{ |
| 23 |
using value_t = boost::math::false_type; |
| 24 |
using type = Default; |
| 25 |
}; |
| 26 |
|
| 27 |
template <typename Default, template<typename...> class Op, typename... Args> |
| 28 |
struct detector<Default, void_t<Op<Args...>>, Op, Args...> |
| 29 |
{ |
| 30 |
using value_t = boost::math::true_type; |
| 31 |
using type = Op<Args...>; |
| 32 |
}; |
| 33 |
|
| 34 |
} // Namespace detail |
| 35 |
|
| 36 |
// Special type to indicate detection failure |
| 37 |
struct nonesuch |
| 38 |
{ |
| 39 |
nonesuch() = delete; |
| 40 |
~nonesuch() = delete; |
| 41 |
nonesuch(const nonesuch&) = delete; |
| 42 |
void operator=(const nonesuch&) = delete; |
| 43 |
}; |
| 44 |
|
| 45 |
template <template<typename...> class Op, typename... Args> |
| 46 |
using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t; |
| 47 |
|
| 48 |
template <template<typename...> class Op, typename... Args> |
| 49 |
using detected_t = typename detail::detector<nonesuch, void, Op, Args...>::type; |
| 50 |
|
| 51 |
template <typename Default, template<typename...> class Op, typename... Args> |
| 52 |
using detected_or = detail::detector<Default, void, Op, Args...>; |
| 53 |
|
| 54 |
}}} // Namespaces boost math tools |
| 55 |
|
| 56 |
#endif // BOOST_MATH_TOOLS_IS_DETECTED_HPP |