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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

52.17
/libs/core/serialization/include/hpx/serialization/vector.hpp
1
//  Copyright (c) 2014 Thomas Heller
2
//  Copyright (c) 2022-2025 Hartmut Kaiser
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#pragma once
9

10
#include <hpx/config.hpp>
11
#include <hpx/assert.hpp>
12
#include <hpx/serialization/array.hpp>
13
#include <hpx/serialization/detail/serialize_collection.hpp>
14
#include <hpx/serialization/serialization_fwd.hpp>
15
#include <hpx/serialization/serialize.hpp>
16
#include <hpx/serialization/traits/is_bitwise_serializable.hpp>
17
#include <hpx/serialization/traits/is_not_bitwise_serializable.hpp>
18

19
#include <cstddef>
20
#include <cstdint>
21
#include <type_traits>
22
#include <vector>
23

24
namespace hpx::serialization {
25

26
    HPX_CXX_EXPORT template <typename Allocator>
27
    void serialize(input_archive& ar, std::vector<bool, Allocator>& v, unsigned)
28
    {
×
29
        std::uint64_t size = 0;
30
        ar >> size;    //-V128
31

32
        v.clear();
33
        if (size == 0)
34
        {
×
35
            return;
36
        }
37

38
        // normal load ... no chance of doing bitwise here ...
39
        v.reserve(size);
40
        for (std::size_t i = 0; i != size; ++i)
×
41
        {
×
42
            bool b = false;
43
            ar >> b;
×
44
            v.push_back(b);
45
        }
×
46
    }
47

48
    HPX_CXX_EXPORT template <typename T, typename Allocator>
49
    void serialize(input_archive& ar, std::vector<T, Allocator>& v, unsigned)
50
    {
7✔
51
        v.clear();
52

3✔
53
        std::uint64_t size;
54
        ar >> size;    //-V128
55
        if (size == 0)
56
        {
7✔
57
            return;
58
        }
59

60
        using element_type =
61
            std::remove_const_t<typename std::vector<T, Allocator>::value_type>;
62

63
        constexpr bool use_optimized =
64
            std::is_default_constructible_v<element_type> &&
65
            (hpx::traits::is_bitwise_serializable_v<element_type> ||
66
                !hpx::traits::is_not_bitwise_serializable_v<element_type>);
67

68
        if constexpr (use_optimized)
69
        {
70
#if !defined(HPX_SERIALIZATION_HAVE_ALL_TYPES_ARE_BITWISE_SERIALIZABLE)
71
            if (ar.disable_array_optimization() || ar.endianess_differs())
72
            {
4✔
73
                detail::load_collection(ar, v, size);
74
                return;
×
75
            }
×
76
#else
77
            HPX_ASSERT(
78
                !(ar.disable_array_optimization() || ar.endianess_differs()));
79
#endif
80
            // bitwise load ...
81
            if (v.size() < size)
82
            {
4✔
83
                v.resize(size);
84
            }
4✔
85

86
            ar >> hpx::serialization::make_array(v.data(), v.size());
87
        }
4✔
88
        else
89
        {
90
            // normal load ...
91
            detail::load_collection(ar, v, size);
92
        }
3✔
93
    }
94

95
    HPX_CXX_EXPORT template <typename Allocator>
96
    void serialize(
97
        output_archive& ar, std::vector<bool, Allocator> const& v, unsigned)
×
98
    {
99
        std::uint64_t const size = v.size();
100
        ar << size;
101
        if (size == 0)
102
        {
×
103
            return;
104
        }
105

106
        // normal save ... no chance of doing bitwise here ...
107
        for (std::size_t i = 0; i < v.size(); ++i)
108
        {
×
109
            bool b = v[i];
110
            ar << b;
111
        }
112
    }
113

114
    HPX_CXX_EXPORT template <typename T, typename Allocator>
115
    void serialize(
116
        output_archive& ar, std::vector<T, Allocator> const& v, unsigned)
19✔
117
    {
118
        std::uint64_t size = v.size();
119
        ar << size;
120
        if (size == 0)
121
        {
19✔
122
            return;
123
        }
124

125
        using element_type =
126
            std::remove_const_t<typename std::vector<T, Allocator>::value_type>;
127

128
        constexpr bool use_optimized =
129
            std::is_default_constructible_v<element_type> &&
130
            (hpx::traits::is_bitwise_serializable_v<element_type> ||
131
                !hpx::traits::is_not_bitwise_serializable_v<element_type>);
132

133
        if constexpr (use_optimized)
134
        {
135
#if !defined(HPX_SERIALIZATION_HAVE_ALL_TYPES_ARE_BITWISE_SERIALIZABLE)
136
            if (ar.disable_array_optimization() || ar.endianess_differs())
137
            {
10✔
138
                detail::save_collection(ar, v);
139
                return;
140
            }
141
#else
142
            HPX_ASSERT(
143
                !(ar.disable_array_optimization() || ar.endianess_differs()));
144
#endif
145
            // bitwise (zero-copy) save ...
146
            ar << hpx::serialization::make_array(v.data(), v.size());
147
        }
10✔
148
        else
149
        {
150
            // normal save ...
151
            detail::save_collection(ar, v);
152
        }
153
    }
154
}    // namespace hpx::serialization
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