File: clamped_uint.hpp

package info (click to toggle)
iqtree 2.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 14,620 kB
  • sloc: cpp: 142,571; ansic: 57,789; sh: 275; python: 242; makefile: 95
file content (43 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef TERRACES_CLAMPED_UINT_HPP
#define TERRACES_CLAMPED_UINT_HPP

#include "definitions.hpp"

#include <iosfwd>

namespace terraces {

template <bool except>
class checked_uint {
	index m_value;

public:
	checked_uint(index value = 0);

	checked_uint<except>& operator+=(checked_uint<except> other);
	checked_uint<except>& operator*=(checked_uint<except> other);
	bool is_clamped() const;
	index value() const;
};

template <bool except>
bool operator==(checked_uint<except> a, checked_uint<except> b);

template <bool except>
bool operator!=(checked_uint<except> a, checked_uint<except> b);

template <bool except>
checked_uint<except> operator+(checked_uint<except> a, checked_uint<except> b);

template <bool except>
checked_uint<except> operator*(checked_uint<except> a, checked_uint<except> b);

template <bool except>
std::ostream& operator<<(std::ostream& stream, checked_uint<except> val);

using clamped_uint = checked_uint<false>;
using overflow_except_uint = checked_uint<true>;

} // namespace terraces

#endif // TERRACES_CLAMPED_UINT_HPP