blob: b74ca21577fa7e870b1d374f092f21fe9d3c0c1f [file] [log] [blame]
Keir Mierle8ebb0732012-04-30 23:09:08 -07001// Ceres Solver - A fast non-linear least squares minimizer
Sergiu Deitsch8b88a9a2022-05-27 01:42:39 +02002// Copyright 2024 Google Inc. All rights reserved.
Keir Mierle7492b0d2015-03-17 22:30:16 -07003// http://ceres-solver.org/
Keir Mierle8ebb0732012-04-30 23:09:08 -07004//
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
31#ifndef CERES_PUBLIC_INTERNAL_PORT_H_
32#define CERES_PUBLIC_INTERNAL_PORT_H_
33
Sergiu Deitsch8b88a9a2022-05-27 01:42:39 +020034#include <cmath> // Necessary for __cpp_lib_math_special_functions feature test
35
Sameer Agarwal9c5f29d2022-02-10 15:15:11 -080036// A macro to mark a function/variable/class as deprecated.
37// We use compiler specific attributes rather than the c++
38// attribute because they do not mix well with each other.
39#if defined(_MSC_VER)
40#define CERES_DEPRECATED_WITH_MSG(message) __declspec(deprecated(message))
41#elif defined(__GNUC__)
42#define CERES_DEPRECATED_WITH_MSG(message) __attribute__((deprecated(message)))
43#else
44// In the worst case fall back to c++ attribute.
Sergiu Deitschf90833f2022-02-07 23:43:19 +010045#define CERES_DEPRECATED_WITH_MSG(message) [[deprecated(message)]]
Taylor Braun-Jones3f6d2732020-01-28 12:09:30 -050046#endif
47
Sergiu Deitsch84265262021-11-25 19:51:13 +010048// Indicates whether C++20 is currently active
49#ifndef CERES_HAS_CPP20
50#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
51#define CERES_HAS_CPP20
52#endif // __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >=
53 // 202002L)
54#endif // !defined(CERES_HAS_CPP20)
55
Sergiu Deitschf0851662022-02-17 00:56:27 +010056// Prevents symbols from being substituted by the corresponding macro definition
57// under the same name. For instance, min and max are defined as macros on
58// Windows (unless NOMINMAX is defined) which causes compilation errors when
59// defining or referencing symbols under the same name.
60//
61// To be robust in all cases particularly when NOMINMAX cannot be used, use this
62// macro to annotate min/max declarations/definitions. Examples:
63//
64// int max CERES_PREVENT_MACRO_SUBSTITUTION();
65// min CERES_PREVENT_MACRO_SUBSTITUTION(a, b);
66// max CERES_PREVENT_MACRO_SUBSTITUTION(a, b);
67//
68// NOTE: In case the symbols for which the substitution must be prevented are
69// used within another macro, the substitution must be inhibited using parens as
70//
71// (std::numerical_limits<double>::max)()
72//
73// since the helper macro will not work here. Do not use this technique in
74// general case, because it will prevent argument-dependent lookup (ADL).
75//
76#define CERES_PREVENT_MACRO_SUBSTITUTION // Yes, it's empty
77
Sergiu Deitsch48933922023-09-30 11:48:32 +020078// CERES_DISABLE_DEPRECATED_WARNING and CERES_RESTORE_DEPRECATED_WARNING allow
79// to temporarily disable deprecation warnings
80#if defined(_MSC_VER)
81#define CERES_DISABLE_DEPRECATED_WARNING \
82 _Pragma("warning(push)") _Pragma("warning(disable : 4996)")
83#define CERES_RESTORE_DEPRECATED_WARNING _Pragma("warning(pop)")
84#else // defined(_MSC_VER)
85#define CERES_DISABLE_DEPRECATED_WARNING
86#define CERES_RESTORE_DEPRECATED_WARNING
87#endif // defined(_MSC_VER)
88
Sergiu Deitsch8b88a9a2022-05-27 01:42:39 +020089#if defined(__cpp_lib_math_special_functions) && \
90 ((__cpp_lib_math_special_functions >= 201603L) || \
91 defined(__STDCPP_MATH_SPEC_FUNCS__) && \
92 (__STDCPP_MATH_SPEC_FUNCS__ >= 201003L))
93// If defined, indicates whether C++17 Bessel functions (of the first kind) are
94// available. Some standard library implementations, such as libc++ (Android
95// NDK, Apple, Clang) do not yet provide these functions. Implementations that
96// do not support C++17, but support ISO 29124:2010, provide the functions if
97// __STDCPP_MATH_SPEC_FUNCS__ is defined by the implementation to a value at
98// least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__ before
99// including any standard library headers. Standard library Bessel functions are
100// preferred over any other implementation.
101#define CERES_HAS_CPP17_BESSEL_FUNCTIONS
102#elif defined(_SVID_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
103// If defined, indicates that j0, j1, and jn from <math.h> are available.
104#define CERES_HAS_POSIX_BESSEL_FUNCTIONS
105#endif
106
Keir Mierle8ebb0732012-04-30 23:09:08 -0700107#endif // CERES_PUBLIC_INTERNAL_PORT_H_