AoC code coverage
Current view: top level - aoclib - IntegerCast.h (source / functions) Coverage Total Hit
Test: master Lines: 100.0 % 8 8
Test Date: 2025-07-28 10:53:57 Functions: 92.3 % 13 12

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include <libassert/assert.hpp>
       4              : 
       5              : #include <concepts>
       6              : #include <limits>
       7              : #include <type_traits>
       8              : 
       9    264337262 : template <std::integral Dst, std::integral Src> constexpr Dst integerCast(Src const &x) {
      10    264337262 :   DEBUG_ASSERT(std::in_range<Dst>(x), x, std::numeric_limits<Dst>::lowest(),
      11    264337262 :                std::numeric_limits<Dst>::max());
      12    264337262 :   return static_cast<Dst>(x);
      13    264337262 : }
      14              : 
      15         1107 : template <std::integral Src> constexpr auto castToSigned(Src const &x) {
      16         1107 :   return integerCast<std::make_signed_t<Src>>(x);
      17         1107 : }
      18              : 
      19              : template <std::integral Src> constexpr auto castToUnsigned(Src const &x) {
      20              :   return integerCast<std::make_unsigned_t<Src>>(x);
      21              : }
        

Generated by: LCOV version 2.0-1