// Copyright (c) 2020-now by the Zeek Project. See LICENSE for details. #pragma once #define SAFEINT_DISABLE_ADDRESS_OPERATOR #include #include namespace hilti::rt::integer { namespace detail { class SafeIntException { public: static void SafeIntOnOverflow() __attribute__((noreturn)) { throw Overflow("integer overflow"); } static void SafeIntOnDivZero() __attribute__((noreturn)) { throw DivisionByZero("integer division by zero"); } }; } // namespace detail template using safe = SafeInt; } // namespace hilti::rt::integer // Needs to be a top level. template inline auto operator<<(O& out, const hilti::rt::integer::safe& x) -> std::enable_if_t, O>& { if ( std::is_same() ) out << static_cast(x); else if ( std::is_same() ) out << static_cast(x); else out << x.Ref(); return out; }