Coverage Report

Created: 2023-06-07 06:37

/src/immer/immer/refcount/unsafe_refcount_policy.hpp
Line
Count
Source (jump to first uncovered line)
1
//
2
// immer: immutable data structures for C++
3
// Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4
//
5
// This software is distributed under the Boost Software License, Version 1.0.
6
// See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7
//
8
9
#pragma once
10
11
#include <immer/refcount/no_refcount_policy.hpp>
12
13
#include <atomic>
14
#include <utility>
15
16
namespace immer {
17
18
/*!
19
 * A reference counting policy implemented using a raw `int` count.
20
 * It is **not thread-safe**.
21
 */
22
struct unsafe_refcount_policy
23
{
24
    mutable int refcount;
25
26
    unsafe_refcount_policy()
27
0
        : refcount{1} {};
28
    unsafe_refcount_policy(disowned)
29
        : refcount{0}
30
0
    {}
31
32
0
    void inc() { ++refcount; }
33
0
    bool dec() { return --refcount == 0; }
34
0
    bool unique() { return refcount == 1; }
35
};
36
37
} // namespace immer