/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2010-2021 Danny Robson */ #pragma once #include "./assert.hpp" #include #define WARN(C) do { \ DEBUG_ONLY ( \ if (C) { \ std::cerr << __FILE__ \ << ":" << __func__ \ << ":" << __LINE__ \ << ", " << #C \ << '\n'; \ } \ ); \ } while (0) #define RETURN_FALSE_UNLESS(CONDITION) do { \ if (const auto &__return_false_unless = (CONDITION); !__return_false_unless) { \ if constexpr (debug_enabled) { \ std::cerr << __FILE__ << ':' \ << __LINE__ << ':' \ << __PRETTY_FUNCTION__ << "; " \ << #CONDITION << '\n'; \ breakpoint (); \ } \ \ return false; \ } \ } while (0) #define WARN_RETURN(CONDITION,VALUE) do { \ if (const auto& __warn_return = (CONDITION); !!__warn_return) { \ if constexpr (debug_enabled) { \ std::cerr << __FILE__ << ':' \ << __LINE__ << ':' \ << __PRETTY_FUNCTION__ << "; " \ << #CONDITION << '\n'; \ breakpoint (); \ } \ \ return (VALUE); \ } \ } while (0) #define WARN_AND_RETURN_IF(COND, VALUE) WARN_RETURN((COND), (VALUE)) #define RETURN_UNLESS(VALUE,CONDITION) do { \ if (const auto &__return_unless = (CONDITION); !__return_unless) { \ if constexpr (debug_enabled) { \ std::cerr << __FILE__ << ':' \ << __LINE__ << ':' \ << __PRETTY_FUNCTION__ << "; " \ << #CONDITION << '\n'; \ breakpoint (); \ } \ \ return (VALUE); \ } \ } while (0) /////////////////////////////////////////////////////////////////////////////// #include #include void warn (void); void warn (std::string const&); void warn (std::string_view); void warn (const char *); template decltype(auto) warn_return ( char const *message, ValueT &&value ) { warn (message); return std::forward (value); }