config.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright (c) 2016-2024 Antony Polukhin
  2. // Copyright (c) 2022 Denis Mikhailov
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PFR_CONFIG_HPP
  7. #define BOOST_PFR_CONFIG_HPP
  8. #pragma once
  9. #if __cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900)
  10. #include <type_traits> // to get non standard platform macro definitions (__GLIBCXX__ for example)
  11. #endif
  12. /// \file boost/pfr/config.hpp
  13. /// Contains all the macros that describe Boost.PFR configuration, like BOOST_PFR_ENABLED
  14. ///
  15. /// \note This header file doesn't require C++14 Standard and supports all C++ compilers, even pre C++14 compilers (C++11, C++03...).
  16. // Reminder:
  17. // * MSVC++ 14.2 _MSC_VER == 1927 <- Loophole is known to work (Visual Studio ????)
  18. // * MSVC++ 14.1 _MSC_VER == 1916 <- Loophole is known to NOT work (Visual Studio 2017)
  19. // * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
  20. // * MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
  21. #ifdef BOOST_PFR_NOT_SUPPORTED
  22. # error Please, do not set BOOST_PFR_NOT_SUPPORTED value manually, use '-DBOOST_PFR_ENABLED=0' instead of it
  23. #endif
  24. #if defined(_MSC_VER)
  25. # if !defined(_MSVC_LANG) || _MSC_VER <= 1900
  26. # define BOOST_PFR_NOT_SUPPORTED 1
  27. # endif
  28. #elif __cplusplus < 201402L
  29. # define BOOST_PFR_NOT_SUPPORTED 1
  30. #endif
  31. #ifndef BOOST_PFR_USE_LOOPHOLE
  32. # if defined(_MSC_VER)
  33. # if _MSC_VER >= 1927
  34. # define BOOST_PFR_USE_LOOPHOLE 1
  35. # else
  36. # define BOOST_PFR_USE_LOOPHOLE 0
  37. # endif
  38. # elif defined(__clang_major__) && __clang_major__ >= 8
  39. # define BOOST_PFR_USE_LOOPHOLE 0
  40. # else
  41. # define BOOST_PFR_USE_LOOPHOLE 1
  42. # endif
  43. #endif
  44. #ifndef BOOST_PFR_USE_CPP17
  45. # ifdef __cpp_structured_bindings
  46. # define BOOST_PFR_USE_CPP17 1
  47. # elif defined(_MSVC_LANG)
  48. # if _MSVC_LANG >= 201703L
  49. # define BOOST_PFR_USE_CPP17 1
  50. # else
  51. # define BOOST_PFR_USE_CPP17 0
  52. # endif
  53. # else
  54. # define BOOST_PFR_USE_CPP17 0
  55. # endif
  56. #endif
  57. #if (!BOOST_PFR_USE_CPP17 && !BOOST_PFR_USE_LOOPHOLE)
  58. # if (defined(_MSC_VER) && _MSC_VER < 1916) ///< in Visual Studio 2017 v15.9 PFR library with classic engine normally works
  59. # define BOOST_PFR_NOT_SUPPORTED 1
  60. # endif
  61. #endif
  62. #ifndef BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE
  63. // Assume that libstdc++ since GCC-7.3 does not have linear instantiation depth in std::make_integral_sequence
  64. # if defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101
  65. # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1
  66. # elif defined(_MSC_VER)
  67. # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1
  68. //# elif other known working lib
  69. # else
  70. # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 0
  71. # endif
  72. #endif
  73. #ifndef BOOST_PFR_HAS_GUARANTEED_COPY_ELISION
  74. # if defined(__cpp_guaranteed_copy_elision) && (!defined(_MSC_VER) || _MSC_VER > 1928)
  75. # define BOOST_PFR_HAS_GUARANTEED_COPY_ELISION 1
  76. # else
  77. # define BOOST_PFR_HAS_GUARANTEED_COPY_ELISION 0
  78. # endif
  79. #endif
  80. #ifndef BOOST_PFR_ENABLE_IMPLICIT_REFLECTION
  81. # if defined(__cpp_lib_is_aggregate)
  82. # define BOOST_PFR_ENABLE_IMPLICIT_REFLECTION 1
  83. # else
  84. // There is no way to detect potential ability to be reflectable without std::is_aggregare
  85. # define BOOST_PFR_ENABLE_IMPLICIT_REFLECTION 0
  86. # endif
  87. #endif
  88. #ifndef BOOST_PFR_CORE_NAME_ENABLED
  89. # if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L))
  90. # if (defined(__cpp_nontype_template_args) && __cpp_nontype_template_args >= 201911) \
  91. || (defined(__clang_major__) && __clang_major__ >= 12)
  92. # define BOOST_PFR_CORE_NAME_ENABLED 1
  93. # else
  94. # define BOOST_PFR_CORE_NAME_ENABLED 0
  95. # endif
  96. # else
  97. # define BOOST_PFR_CORE_NAME_ENABLED 0
  98. # endif
  99. #endif
  100. #ifndef BOOST_PFR_CORE_NAME_PARSING
  101. # if defined(_MSC_VER) && !defined(__clang__)
  102. # define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto __cdecl boost::pfr::detail::name_of_field_impl<") - 1, sizeof(">(void) noexcept") - 1, backward("->"))
  103. # elif defined(__clang__)
  104. # define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto boost::pfr::detail::name_of_field_impl() [MsvcWorkaround = ") - 1, sizeof("}]") - 1, backward("."))
  105. # elif defined(__GNUC__)
  106. # define BOOST_PFR_CORE_NAME_PARSING (sizeof("consteval auto boost::pfr::detail::name_of_field_impl() [with MsvcWorkaround = ") - 1, sizeof(")]") - 1, backward("::"))
  107. # else
  108. // Default parser for other platforms... Just skip nothing!
  109. # define BOOST_PFR_CORE_NAME_PARSING (0, 0, "")
  110. # endif
  111. #endif
  112. #if defined(__has_cpp_attribute)
  113. # if __has_cpp_attribute(maybe_unused)
  114. # define BOOST_PFR_MAYBE_UNUSED [[maybe_unused]]
  115. # endif
  116. #endif
  117. #ifndef BOOST_PFR_MAYBE_UNUSED
  118. # define BOOST_PFR_MAYBE_UNUSED
  119. #endif
  120. #ifndef BOOST_PFR_ENABLED
  121. # ifdef BOOST_PFR_NOT_SUPPORTED
  122. # define BOOST_PFR_ENABLED 0
  123. # else
  124. # define BOOST_PFR_ENABLED 1
  125. # endif
  126. #endif
  127. #undef BOOST_PFR_NOT_SUPPORTED
  128. #endif // BOOST_PFR_CONFIG_HPP