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