detected.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // __ _____ _____ _____
  2. // __| | __| | | | JSON for Modern C++
  3. // | | |__ | | | | | | version 3.11.3
  4. // |_____|_____|_____|_|___| https://github.com/nlohmann/json
  5. //
  6. // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
  7. // SPDX-License-Identifier: MIT
  8. #pragma once
  9. #include <type_traits>
  10. #include <nlohmann/detail/meta/void_t.hpp>
  11. NLOHMANN_JSON_NAMESPACE_BEGIN
  12. namespace detail
  13. {
  14. // https://en.cppreference.com/w/cpp/experimental/is_detected
  15. struct nonesuch
  16. {
  17. nonesuch() = delete;
  18. ~nonesuch() = delete;
  19. nonesuch(nonesuch const&) = delete;
  20. nonesuch(nonesuch const&&) = delete;
  21. void operator=(nonesuch const&) = delete;
  22. void operator=(nonesuch&&) = delete;
  23. };
  24. template<class Default,
  25. class AlwaysVoid,
  26. template<class...> class Op,
  27. class... Args>
  28. struct detector
  29. {
  30. using value_t = std::false_type;
  31. using type = Default;
  32. };
  33. template<class Default, template<class...> class Op, class... Args>
  34. struct detector<Default, void_t<Op<Args...>>, Op, Args...>
  35. {
  36. using value_t = std::true_type;
  37. using type = Op<Args...>;
  38. };
  39. template<template<class...> class Op, class... Args>
  40. using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
  41. template<template<class...> class Op, class... Args>
  42. struct is_detected_lazy : is_detected<Op, Args...> { };
  43. template<template<class...> class Op, class... Args>
  44. using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
  45. template<class Default, template<class...> class Op, class... Args>
  46. using detected_or = detector<Default, void, Op, Args...>;
  47. template<class Default, template<class...> class Op, class... Args>
  48. using detected_or_t = typename detected_or<Default, Op, Args...>::type;
  49. template<class Expected, template<class...> class Op, class... Args>
  50. using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
  51. template<class To, template<class...> class Op, class... Args>
  52. using is_detected_convertible =
  53. std::is_convertible<detected_t<Op, Args...>, To>;
  54. } // namespace detail
  55. NLOHMANN_JSON_NAMESPACE_END