port.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Ceres Solver - A fast non-linear least squares minimizer
  2. // Copyright 2023 Google Inc. All rights reserved.
  3. // http://ceres-solver.org/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright notice,
  9. // this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. // * Neither the name of Google Inc. nor the names of its contributors may be
  14. // used to endorse or promote products derived from this software without
  15. // specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. // POSSIBILITY OF SUCH DAMAGE.
  28. //
  29. // Author: keir@google.com (Keir Mierle)
  30. #ifndef CERES_PUBLIC_INTERNAL_PORT_H_
  31. #define CERES_PUBLIC_INTERNAL_PORT_H_
  32. // A macro to mark a function/variable/class as deprecated.
  33. // We use compiler specific attributes rather than the c++
  34. // attribute because they do not mix well with each other.
  35. #if defined(_MSC_VER)
  36. #define CERES_DEPRECATED_WITH_MSG(message) __declspec(deprecated(message))
  37. #elif defined(__GNUC__)
  38. #define CERES_DEPRECATED_WITH_MSG(message) __attribute__((deprecated(message)))
  39. #else
  40. // In the worst case fall back to c++ attribute.
  41. #define CERES_DEPRECATED_WITH_MSG(message) [[deprecated(message)]]
  42. #endif
  43. #ifndef CERES_GET_FLAG
  44. #define CERES_GET_FLAG(X) X
  45. #endif
  46. // Indicates whether C++20 is currently active
  47. #ifndef CERES_HAS_CPP20
  48. #if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
  49. #define CERES_HAS_CPP20
  50. #endif // __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >=
  51. // 202002L)
  52. #endif // !defined(CERES_HAS_CPP20)
  53. // Prevents symbols from being substituted by the corresponding macro definition
  54. // under the same name. For instance, min and max are defined as macros on
  55. // Windows (unless NOMINMAX is defined) which causes compilation errors when
  56. // defining or referencing symbols under the same name.
  57. //
  58. // To be robust in all cases particularly when NOMINMAX cannot be used, use this
  59. // macro to annotate min/max declarations/definitions. Examples:
  60. //
  61. // int max CERES_PREVENT_MACRO_SUBSTITUTION();
  62. // min CERES_PREVENT_MACRO_SUBSTITUTION(a, b);
  63. // max CERES_PREVENT_MACRO_SUBSTITUTION(a, b);
  64. //
  65. // NOTE: In case the symbols for which the substitution must be prevented are
  66. // used within another macro, the substitution must be inhibited using parens as
  67. //
  68. // (std::numerical_limits<double>::max)()
  69. //
  70. // since the helper macro will not work here. Do not use this technique in
  71. // general case, because it will prevent argument-dependent lookup (ADL).
  72. //
  73. #define CERES_PREVENT_MACRO_SUBSTITUTION // Yes, it's empty
  74. // CERES_DISABLE_DEPRECATED_WARNING and CERES_RESTORE_DEPRECATED_WARNING allow
  75. // to temporarily disable deprecation warnings
  76. #if defined(_MSC_VER)
  77. #define CERES_DISABLE_DEPRECATED_WARNING \
  78. _Pragma("warning(push)") _Pragma("warning(disable : 4996)")
  79. #define CERES_RESTORE_DEPRECATED_WARNING _Pragma("warning(pop)")
  80. #else // defined(_MSC_VER)
  81. #define CERES_DISABLE_DEPRECATED_WARNING
  82. #define CERES_RESTORE_DEPRECATED_WARNING
  83. #endif // defined(_MSC_VER)
  84. #endif // CERES_PUBLIC_INTERNAL_PORT_H_