|
8 | 8 | #include <Kokkos_Core.hpp>
|
9 | 9 | #include <vector>
|
10 | 10 | #include <set>
|
11 |
| -#include <string> |
| 11 | +#include <sstream> |
12 | 12 | #include <algorithm>
|
13 | 13 | #include <numeric>
|
14 | 14 | #include "KokkosFFT_traits.hpp"
|
|
20 | 20 | __FUNCTION__)
|
21 | 21 | #else
|
22 | 22 | #include <source_location>
|
23 |
| -#define KOKKOSFFT_EXPECTS(expression, msg) \ |
24 |
| - KokkosFFT::Impl::check_precondition((expression), msg, \ |
25 |
| - std::source_location::current()) |
| 23 | +#define KOKKOSFFT_EXPECTS(expression, msg) \ |
| 24 | + KokkosFFT::Impl::check_precondition( \ |
| 25 | + (expression), msg, std::source_location::current().file_name(), \ |
| 26 | + std::source_location::current().line(), \ |
| 27 | + std::source_location::current().function_name(), \ |
| 28 | + std::source_location::current().column()) |
26 | 29 | #endif
|
27 | 30 |
|
28 | 31 | namespace KokkosFFT {
|
29 | 32 | namespace Impl {
|
30 | 33 |
|
31 |
| -#if defined(KOKKOS_ENABLE_CXX17) |
32 |
| -inline void check_precondition(const bool expression, const std::string& msg, |
33 |
| - const char* file_name, int line, |
34 |
| - const char* function_name) { |
| 34 | +inline void check_precondition(const bool expression, |
| 35 | + [[maybe_unused]] const std::string& msg, |
| 36 | + [[maybe_unused]] const char* file_name, int line, |
| 37 | + [[maybe_unused]] const char* function_name, |
| 38 | + [[maybe_unused]] const int column = -1) { |
| 39 | + // Quick return if possible |
| 40 | + if (expression) return; |
| 41 | + |
35 | 42 | std::stringstream ss("file: ");
|
36 |
| - ss << file_name << '(' << line << ") `" << function_name << "`: " << msg |
37 |
| - << '\n'; |
38 |
| - if (!expression) { |
39 |
| - throw std::runtime_error(ss.str()); |
| 43 | + if (column == -1) { |
| 44 | + // For C++ 17 |
| 45 | + ss << file_name << '(' << line << ") `" << function_name << "`: " << msg |
| 46 | + << '\n'; |
| 47 | + } else { |
| 48 | + // For C++ 20 and later |
| 49 | + ss << file_name << '(' << line << ':' << column << ") `" << function_name |
| 50 | + << "`: " << msg << '\n'; |
40 | 51 | }
|
| 52 | + throw std::runtime_error(ss.str()); |
41 | 53 | }
|
42 |
| -#else |
43 |
| -inline void check_precondition(const bool expression, const std::string& msg, |
44 |
| - std::source_location location) { |
45 |
| - std::stringstream ss("file: "); |
46 |
| - ss << location.file_name() << '(' << location.line() << ':' |
47 |
| - << location.column() << ") `" << location.function_name() << "`: " << msg |
48 |
| - << '\n'; |
49 | 54 |
|
50 |
| - if (!expression) { |
51 |
| - throw std::runtime_error(ss.str()); |
52 |
| - } |
53 |
| -} |
54 |
| -#endif |
55 | 55 | template <typename ViewType>
|
56 | 56 | auto convert_negative_axis(ViewType, int _axis = -1) {
|
57 | 57 | static_assert(Kokkos::is_view<ViewType>::value,
|
|
0 commit comments