From 2a1d1d9302e1cb3b75566c56d093574dc968bfe8 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Mon, 29 Jul 2024 22:02:31 +0900 Subject: [PATCH] simplify check_precondition --- common/src/KokkosFFT_utils.hpp | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/common/src/KokkosFFT_utils.hpp b/common/src/KokkosFFT_utils.hpp index b7a3ad3b..f83c9d39 100644 --- a/common/src/KokkosFFT_utils.hpp +++ b/common/src/KokkosFFT_utils.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include "KokkosFFT_traits.hpp" @@ -20,38 +20,38 @@ __FUNCTION__) #else #include -#define KOKKOSFFT_EXPECTS(expression, msg) \ - KokkosFFT::Impl::check_precondition((expression), msg, \ - std::source_location::current()) +#define KOKKOSFFT_EXPECTS(expression, msg) \ + KokkosFFT::Impl::check_precondition( \ + (expression), msg, std::source_location::current().file_name(), \ + std::source_location::current().line(), \ + std::source_location::current().function_name(), \ + std::source_location::current().column()) #endif namespace KokkosFFT { namespace Impl { -#if defined(KOKKOS_ENABLE_CXX17) -inline void check_precondition(const bool expression, const std::string& msg, - const char* file_name, int line, - const char* function_name) { +inline void check_precondition(const bool expression, + [[maybe_unused]] const std::string& msg, + [[maybe_unused]] const char* file_name, int line, + [[maybe_unused]] const char* function_name, + [[maybe_unused]] const int column = -1) { + // Quick return if possible + if (expression) return; + std::stringstream ss("file: "); - ss << file_name << '(' << line << ") `" << function_name << "`: " << msg - << '\n'; - if (!expression) { - throw std::runtime_error(ss.str()); + if (column == -1) { + // For C++ 17 + ss << file_name << '(' << line << ") `" << function_name << "`: " << msg + << '\n'; + } else { + // For C++ 20 and later + ss << file_name << '(' << line << ':' << column << ") `" << function_name + << "`: " << msg << '\n'; } + throw std::runtime_error(ss.str()); } -#else -inline void check_precondition(const bool expression, const std::string& msg, - std::source_location location) { - std::stringstream ss("file: "); - ss << location.file_name() << '(' << location.line() << ':' - << location.column() << ") `" << location.function_name() << "`: " << msg - << '\n'; - if (!expression) { - throw std::runtime_error(ss.str()); - } -} -#endif template auto convert_negative_axis(ViewType, int _axis = -1) { static_assert(Kokkos::is_view::value,