2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-01-02 14:42:31 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/port/platform.h"
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
#if !TD_WINDOWS
|
|
|
|
using size_t = std::size_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using int8 = std::int8_t;
|
|
|
|
using int16 = std::int16_t;
|
|
|
|
using uint16 = std::uint16_t;
|
|
|
|
using int32 = std::int32_t;
|
|
|
|
using uint32 = std::uint32_t;
|
|
|
|
using int64 = std::int64_t;
|
|
|
|
using uint64 = std::uint64_t;
|
|
|
|
|
|
|
|
static_assert(sizeof(std::uint8_t) == sizeof(unsigned char), "Unsigned char expected to be 8-bit");
|
|
|
|
using uint8 = unsigned char;
|
|
|
|
|
|
|
|
#if TD_MSVC
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4309)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static_assert(static_cast<char>(128) == -128 || static_cast<char>(128) == 128,
|
|
|
|
"Unexpected cast to char implementation-defined behaviour");
|
|
|
|
static_assert(static_cast<char>(256) == 0, "Unexpected cast to char implementation-defined behaviour");
|
|
|
|
static_assert(static_cast<char>(-256) == 0, "Unexpected cast to char implementation-defined behaviour");
|
|
|
|
|
|
|
|
#if TD_MSVC
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <size_t size>
|
|
|
|
struct UInt {
|
|
|
|
static_assert(size % 8 == 0, "size should be divisible by 8");
|
|
|
|
uint8 raw[size / 8];
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t size>
|
|
|
|
inline bool operator==(const UInt<size> &a, const UInt<size> &b) {
|
2018-02-01 14:01:16 +01:00
|
|
|
return std::memcmp(a.raw, b.raw, sizeof(a.raw)) == 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t size>
|
|
|
|
inline bool operator!=(const UInt<size> &a, const UInt<size> &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
using UInt128 = UInt<128>;
|
|
|
|
using UInt256 = UInt<256>;
|
|
|
|
|
|
|
|
} // namespace td
|