• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PeterCDMcLean / BitLib / 15932764221

27 Jun 2025 05:56PM UTC coverage: 53.989% (-0.1%) from 54.11%
15932764221

Pull #20

github

web-flow
Merge f5f5bad86 into d917039b0
Pull Request #20: Pipecleaning policy and casting issues

10137 of 18766 branches covered (54.02%)

Branch coverage included in aggregate %.

12 of 14 new or added lines in 6 files covered. (85.71%)

4 existing lines in 1 file now uncovered.

6058 of 11231 relevant lines covered (53.94%)

7733697.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.86
/include/bitlib/bit-containers/bit_policy.hpp
1
// ================================= BIT_ARRAY_REF =================================== //
2
// Project:     The Experimental Bit Algorithms Library
3
// \file        bit_array_ref.hpp
4
// Description: Implementation of bit_array_ref
5
// Creator:     Vincent Reverdy
6
// Contributor: Peter McLean [2025]
7
// License:     BSD 3-Clause License
8
// ========================================================================== //
9
#ifndef _BIT_POLICY_HPP_INCLUDED
10
#define _BIT_POLICY_HPP_INCLUDED
11

12
#include "bitlib/bit_concepts.hpp"
13
#include "bitlib/bit-algorithms/bit_algorithm.hpp"
14
#include "bitlib/bit-iterator/bit.hpp"
15
#include "bitlib/bit-iterator/bit_details.hpp"
16

17
namespace bit::policy {
18

19
struct truncate;
20
struct sign_extend;
21
template <typename W>
22
struct typical {
23
  using allocator = std::allocator<std::remove_const_t<W>>;
24
  using extension = sign_extend;
25
  using truncation = truncate;
26
};
27

28
struct truncate {
29
  template <std::integral U, std::size_t N>
30
  constexpr static void to_integral(const bit_sized_range auto& value, U& integral) noexcept {
×
31
    bit_pointer<U> integral_begin(&integral);
×
32
    ::bit::copy(value.begin(), value.begin() + bitsof<U>(), integral_begin);
×
33
  }
×
34
  template <std::integral U, std::size_t N>
35
  constexpr static void from_integral(bit_sized_range auto& value, const U& integral) noexcept {
40✔
36
    const bit_pointer<const U> integral_begin(&integral);
40✔
37
    if constexpr (N == std::dynamic_extent) {
38
      ::bit::copy(integral_begin, integral_begin + value.size(), value.begin());
39
    } else {
20✔
40
      ::bit::copy(integral_begin, integral_begin + N, value.begin());
40✔
41
    }
20✔
42
  }
40✔
43
};
44

45
struct sign_extend {
46
  template <std::integral U, std::size_t N>
47
  constexpr static void to_integral(const bit_sized_range auto& value, U& integral) noexcept {
48
    bit_pointer<U> integral_begin(&integral);
49
    if constexpr (N == std::dynamic_extent) {
50
      if constexpr (std::is_signed_v<U>) {
51
        if (value.last()[-1]) {
52
          ::bit::fill(integral_begin + value.size(), integral_begin + bitsof<U>(), bit1);
53
        }
54
      }
55
    } else {
56
      if constexpr (std::is_signed_v<U>) {
57
        if (value.begin()[N - 1]) {
58
          ::bit::fill(integral_begin + value.size(), integral_begin + bitsof<U>(), bit1);
59
        }
60
      }
61
    }
62
  }
63
  template <std::integral U, std::size_t N>
UNCOV
64
  constexpr static void to_integral(const bit_sized_range auto& value, U& integral, detail::uninitialized_t) noexcept {
×
UNCOV
65
    bit_pointer<U> integral_begin(&integral);
×
UNCOV
66
    if constexpr (N == std::dynamic_extent) {
NEW
67
      ::bit::fill(integral_begin + value.size(), integral_begin + bitsof<U>(), value.end()[-1]);
×
68
    } else {
69
      ::bit::fill(integral_begin + N, integral_begin + bitsof<U>(), value.begin()[N - 1]);
70
    }
UNCOV
71
  }
×
72
  template <std::integral U, std::size_t N = std::dynamic_extent>
73
  constexpr static void from_integral(bit_sized_range auto& value, const U& integral) noexcept {
74
    if constexpr (N == std::dynamic_extent) {
75
      if constexpr (std::is_signed_v<U>) {
76
        if (integral < 0) {
77
          ::bit::fill(value.begin() + bitsof<U>(), value.end(), bit1);
78
        }
79
      }
80
    } else {
81
      if constexpr (std::is_signed_v<U>) {
82
        if (integral < 0) {
83
          ::bit::fill(value.begin() + N, value.end(), bit1);
84
        }
85
      }
86
    }
87
  }
88
  template <std::integral U, std::size_t N = std::dynamic_extent>
89
  constexpr static void from_integral(bit_sized_range auto& value, const U& integral, detail::uninitialized_t) noexcept {
90
    if constexpr (N == std::dynamic_extent) {
91
      ::bit::fill(value.begin() + bitsof<U>(), value.end(), (integral < 0) ? bit1 : bit0);
92
    } else {
93
      ::bit::fill(value.begin() + N, value.end(), (integral < 0) ? bit1 : bit0);
94
    }
95
  }
96
};
97

98
}  // namespace bit::policy
99

100
#endif  // _BIT_POLICY_HPP_INCLUDED
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc