Horizon
macro_scope.hpp
1 #pragma once
2 
3 // This file contains all internal macro definitions
4 // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
5 
6 // exclude unsupported compilers
7 #if defined(__clang__)
8  #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
9  #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
10  #endif
11 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
12  #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
13  #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
14  #endif
15 #endif
16 
17 // disable float-equal warnings on GCC/clang
18 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
19  #pragma GCC diagnostic push
20  #pragma GCC diagnostic ignored "-Wfloat-equal"
21 #endif
22 
23 // disable documentation warnings on clang
24 #if defined(__clang__)
25  #pragma GCC diagnostic push
26  #pragma GCC diagnostic ignored "-Wdocumentation"
27 #endif
28 
29 // allow for portable deprecation warnings
30 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
31  #define JSON_DEPRECATED __attribute__((deprecated))
32 #elif defined(_MSC_VER)
33  #define JSON_DEPRECATED __declspec(deprecated)
34 #else
35  #define JSON_DEPRECATED
36 #endif
37 
38 // allow to disable exceptions
39 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
40  #define JSON_THROW(exception) throw exception
41  #define JSON_TRY try
42  #define JSON_CATCH(exception) catch(exception)
43 #else
44  #define JSON_THROW(exception) std::abort()
45  #define JSON_TRY if(true)
46  #define JSON_CATCH(exception) if(false)
47 #endif
48 
49 // override exception macros
50 #if defined(JSON_THROW_USER)
51  #undef JSON_THROW
52  #define JSON_THROW JSON_THROW_USER
53 #endif
54 #if defined(JSON_TRY_USER)
55  #undef JSON_TRY
56  #define JSON_TRY JSON_TRY_USER
57 #endif
58 #if defined(JSON_CATCH_USER)
59  #undef JSON_CATCH
60  #define JSON_CATCH JSON_CATCH_USER
61 #endif
62 
63 // manual branch prediction
64 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
65  #define JSON_LIKELY(x) __builtin_expect(!!(x), 1)
66  #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
67 #else
68  #define JSON_LIKELY(x) x
69  #define JSON_UNLIKELY(x) x
70 #endif
71 
72 // C++ language standard detection
73 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
74  #define JSON_HAS_CPP_17
75  #define JSON_HAS_CPP_14
76 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
77  #define JSON_HAS_CPP_14
78 #endif
79 
80 // Ugly macros to avoid uglier copy-paste when specializing basic_json. They
81 // may be removed in the future once the class is split.
82 
83 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
84  template<template<typename, typename, typename...> class ObjectType, \
85  template<typename, typename...> class ArrayType, \
86  class StringType, class BooleanType, class NumberIntegerType, \
87  class NumberUnsignedType, class NumberFloatType, \
88  template<typename> class AllocatorType, \
89  template<typename, typename = void> class JSONSerializer>
90 
91 #define NLOHMANN_BASIC_JSON_TPL \
92  basic_json<ObjectType, ArrayType, StringType, BooleanType, \
93  NumberIntegerType, NumberUnsignedType, NumberFloatType, \
94  AllocatorType, JSONSerializer>
95 
106 #define NLOHMANN_JSON_HAS_HELPER(type) \
107  template<typename T> struct has_##type { \
108  private: \
109  template<typename U, typename = typename U::type> \
110  static int detect(U &&); \
111  static void detect(...); \
112  public: \
113  static constexpr bool value = \
114  std::is_integral<decltype(detect(std::declval<T>()))>::value; \
115  }