2018-07-24 11:22:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
#include <nlohmann/detail/meta/void_t.hpp>
|
|
|
|
|
2020-02-02 09:29:37 +00:00
|
|
|
// https://en.cppreference.com/w/cpp/experimental/is_detected
|
2018-07-24 11:22:44 +00:00
|
|
|
namespace nlohmann
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
struct nonesuch
|
|
|
|
{
|
|
|
|
nonesuch() = delete;
|
|
|
|
~nonesuch() = delete;
|
|
|
|
nonesuch(nonesuch const&) = delete;
|
2019-03-17 11:01:49 +00:00
|
|
|
nonesuch(nonesuch const&&) = delete;
|
2018-07-24 11:22:44 +00:00
|
|
|
void operator=(nonesuch const&) = delete;
|
2019-03-17 11:01:49 +00:00
|
|
|
void operator=(nonesuch&&) = delete;
|
2018-07-24 11:22:44 +00:00
|
|
|
};
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<class Default,
|
|
|
|
class AlwaysVoid,
|
|
|
|
template<class...> class Op,
|
|
|
|
class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
struct detector
|
|
|
|
{
|
|
|
|
using value_t = std::false_type;
|
|
|
|
using type = Default;
|
|
|
|
};
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<class Default, template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
struct detector<Default, void_t<Op<Args...>>, Op, Args...>
|
|
|
|
{
|
|
|
|
using value_t = std::true_type;
|
|
|
|
using type = Op<Args...>;
|
|
|
|
};
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<class Default, template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
using detected_or = detector<Default, void, Op, Args...>;
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<class Default, template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<class Expected, template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
|
|
|
|
|
2020-06-03 12:20:36 +00:00
|
|
|
template<class To, template<class...> class Op, class... Args>
|
2018-07-24 11:22:44 +00:00
|
|
|
using is_detected_convertible =
|
|
|
|
std::is_convertible<detected_t<Op, Args...>, To>;
|
2018-10-07 16:39:18 +00:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace nlohmann
|