LCOV - code coverage report
Current view: top level - src/sl3 - utils.hpp (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 100.0 % 21 21
Test Date: 2026-03-17 13:39:52 Functions: 100.0 % 11 11
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #pragma once
       2                 :             : 
       3                 :             : #include <cassert>
       4                 :             : #include <cstddef>
       5                 :             : #include <limits>
       6                 :             : 
       7                 :             : namespace sl3
       8                 :             : {
       9                 :             : 
      10                 :             :   inline size_t
      11                 :         430 :   as_size_t (int val)
      12                 :             :   {
      13                 :         430 :     assert (val >= 0); // LCOV_EXCL_BR_LINE
      14                 :         430 :     return static_cast<size_t> (val);
      15                 :             :   }
      16                 :             : 
      17                 :             :   inline size_t
      18                 :          12 :   as_size_t (ptrdiff_t val)
      19                 :             :   {
      20                 :          12 :     assert (val >= 0); // LCOV_EXCL_BR_LINE
      21                 :          12 :     return static_cast<size_t> (val);
      22                 :             :   }
      23                 :             : 
      24                 :             :   inline int
      25                 :           8 :   as_int (size_t val)
      26                 :             :   {
      27                 :           8 :     assert (val < std::numeric_limits<int>::max ()); // LCOV_EXCL_BR_LINE
      28                 :           8 :     return static_cast<int> (val);
      29                 :             :   }
      30                 :             : 
      31                 :             :   template <typename T1, typename T2>
      32                 :             :   bool
      33                 :          10 :   is_less (const T1& a, const T2& b)
      34                 :             :   {
      35                 :             :     using common_type = std::common_type_t<T1, T2>;
      36                 :          20 :     return std::less<common_type>{}(static_cast<common_type> (a),
      37                 :          10 :                                     static_cast<common_type> (b));
      38                 :             :   }
      39                 :             : 
      40                 :             :   template <typename T1, typename T2>
      41                 :             :   bool
      42                 :           3 :   is_greater (const T1& a, const T2& b)
      43                 :             :   {
      44                 :             :     using common_type = std::common_type_t<T1, T2>;
      45                 :           6 :     return std::greater<common_type>{}(static_cast<common_type> (a),
      46                 :           3 :                                        static_cast<common_type> (b));
      47                 :             :   }
      48                 :             : 
      49                 :             :   template <typename T1, typename T2>
      50                 :             :   bool
      51                 :           3 :   is_less_equal (const T1& a, const T2& b)
      52                 :             :   {
      53                 :             :     using common_type = std::common_type_t<T1, T2>;
      54                 :           6 :     return std::less_equal<common_type>{}(static_cast<common_type> (a),
      55                 :           3 :                                           static_cast<common_type> (b));
      56                 :             :   }
      57                 :             : 
      58                 :             :   template <typename T1, typename T2>
      59                 :             :   bool
      60                 :           4 :   is_equal (const T1& a, const T2& b)
      61                 :             :   {
      62                 :             :     using common_type = std::common_type_t<T1, T2>;
      63                 :           8 :     return std::equal_to<common_type>{}(static_cast<common_type> (a),
      64                 :           4 :                                         static_cast<common_type> (b));
      65                 :             :   }
      66                 :             : 
      67                 :             : }
        

Generated by: LCOV version 2.0-1