log A record for block list
[ghsmtp.git] / Pill.hpp
blob392562e3fd8e65a8181a6fdcbdc5cf51bd88ac9d
1 #ifndef PILL_DOT_HPP
2 #define PILL_DOT_HPP
4 #include <climits>
5 #include <cstddef>
6 #include <cstring>
7 #include <ostream>
8 #include <string_view>
10 // A pill is a unit of entropy.
12 class Pill {
13 public:
14 Pill();
16 bool operator==(Pill const& that) const { return this->s_ == that.s_; }
17 bool operator!=(Pill const& that) const { return !(*this == that); }
19 std::string_view as_string_view() const
21 return std::string_view{b32_str_, strlen(b32_str_)};
24 private:
25 unsigned long long s_;
27 auto static constexpr b32_ndigits_ = ((sizeof(s_) * CHAR_BIT) + 4) / 5;
28 char b32_str_[b32_ndigits_ + 1];
30 friend std::ostream& operator<<(std::ostream& s, Pill const& p)
32 return s << p.b32_str_;
36 #endif // PILL_DOT_HPP