add some noexcept and assume std::function is not nothrow move constructible on clang
This commit is contained in:
parent
37d85ac2f7
commit
11a8f46921
|
@ -175,11 +175,7 @@ TORRENT_VERSION_NAMESPACE_2
|
|||
// or encrypt the content on disk for instance. For more information
|
||||
// about the storage_interface that needs to be implemented for a custom
|
||||
// storage, see storage_interface.
|
||||
#ifdef __clang__
|
||||
storage_constructor_type storage;
|
||||
#else
|
||||
aux::noexcept_movable<storage_constructor_type> storage;
|
||||
#endif
|
||||
|
||||
// The ``userdata`` parameter is optional and will be passed on to the
|
||||
// extension constructor functions, if any
|
||||
|
|
|
@ -77,10 +77,10 @@ namespace libtorrent {
|
|||
}
|
||||
|
||||
// query bit at ``index``. Returns true if bit is 1, otherwise false.
|
||||
bool operator[](int index) const
|
||||
bool operator[](int index) const noexcept
|
||||
{ return get_bit(index); }
|
||||
|
||||
bool get_bit(int index) const
|
||||
bool get_bit(int index) const noexcept
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0);
|
||||
TORRENT_ASSERT(index < size());
|
||||
|
@ -88,13 +88,13 @@ namespace libtorrent {
|
|||
}
|
||||
|
||||
// set bit at ``index`` to 0 (clear_bit) or 1 (set_bit).
|
||||
void clear_bit(int index)
|
||||
void clear_bit(int index) noexcept
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0);
|
||||
TORRENT_ASSERT(index < size());
|
||||
buf()[index / 32] &= aux::host_to_network(~(0x80000000 >> (index & 31)));
|
||||
}
|
||||
void set_bit(int index)
|
||||
void set_bit(int index) noexcept
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0);
|
||||
TORRENT_ASSERT(index < size());
|
||||
|
@ -125,17 +125,17 @@ namespace libtorrent {
|
|||
return bits;
|
||||
}
|
||||
|
||||
int num_words() const
|
||||
int num_words() const noexcept
|
||||
{
|
||||
return (size() + 31) / 32;
|
||||
}
|
||||
|
||||
// returns true if the bitfield has zero size.
|
||||
bool empty() const { return size() == 0; }
|
||||
bool empty() const noexcept { return size() == 0; }
|
||||
|
||||
// returns a pointer to the internal buffer of the bitfield.
|
||||
char const* data() const { return m_buf ? reinterpret_cast<char const*>(&m_buf[1]) : nullptr; }
|
||||
char* data() { return m_buf ? reinterpret_cast<char*>(&m_buf[1]) : nullptr; }
|
||||
char const* data() const noexcept { return m_buf ? reinterpret_cast<char const*>(&m_buf[1]) : nullptr; }
|
||||
char* data() noexcept { return m_buf ? reinterpret_cast<char*>(&m_buf[1]) : nullptr; }
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
TORRENT_DEPRECATED
|
||||
|
@ -151,7 +151,7 @@ namespace libtorrent {
|
|||
|
||||
bitfield& operator=(bitfield&& rhs) noexcept = default;
|
||||
|
||||
void swap(bitfield& rhs)
|
||||
void swap(bitfield& rhs) noexcept
|
||||
{
|
||||
std::swap(m_buf, rhs.m_buf);
|
||||
}
|
||||
|
@ -171,19 +171,19 @@ namespace libtorrent {
|
|||
using reference = bool&;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
bool operator*() { return (*buf & aux::host_to_network(bit)) != 0; }
|
||||
const_iterator& operator++() { inc(); return *this; }
|
||||
const_iterator operator++(int)
|
||||
bool operator*() noexcept { return (*buf & aux::host_to_network(bit)) != 0; }
|
||||
const_iterator& operator++() noexcept { inc(); return *this; }
|
||||
const_iterator operator++(int) noexcept
|
||||
{ const_iterator ret(*this); inc(); return ret; }
|
||||
const_iterator& operator--() { dec(); return *this; }
|
||||
const_iterator operator--(int)
|
||||
const_iterator& operator--() noexcept { dec(); return *this; }
|
||||
const_iterator operator--(int) noexcept
|
||||
{ const_iterator ret(*this); dec(); return ret; }
|
||||
|
||||
const_iterator() {}
|
||||
bool operator==(const_iterator const& rhs) const
|
||||
const_iterator() noexcept {}
|
||||
bool operator==(const_iterator const& rhs) const noexcept
|
||||
{ return buf == rhs.buf && bit == rhs.bit; }
|
||||
|
||||
bool operator!=(const_iterator const& rhs) const
|
||||
bool operator!=(const_iterator const& rhs) const noexcept
|
||||
{ return buf != rhs.buf || bit != rhs.bit; }
|
||||
|
||||
private:
|
||||
|
@ -219,8 +219,8 @@ namespace libtorrent {
|
|||
std::uint32_t bit = 0x80000000;
|
||||
};
|
||||
|
||||
const_iterator begin() const { return const_iterator(m_buf ? buf() : nullptr, 0); }
|
||||
const_iterator end() const { return const_iterator(
|
||||
const_iterator begin() const noexcept { return const_iterator(m_buf ? buf() : nullptr, 0); }
|
||||
const_iterator end() const noexcept { return const_iterator(
|
||||
m_buf ? buf() + num_words() - (((size() & 31) == 0) ? 0 : 1) : nullptr, size() & 31); }
|
||||
|
||||
// set the size of the bitfield to ``bits`` length. If the bitfield is extended,
|
||||
|
@ -229,26 +229,26 @@ namespace libtorrent {
|
|||
void resize(int bits);
|
||||
|
||||
// set all bits in the bitfield to 1 (set_all) or 0 (clear_all).
|
||||
void set_all()
|
||||
void set_all() noexcept
|
||||
{
|
||||
if (size() == 0) return;
|
||||
std::memset(buf(), 0xff, std::size_t(num_words() * 4));
|
||||
clear_trailing_bits();
|
||||
}
|
||||
void clear_all()
|
||||
void clear_all() noexcept
|
||||
{
|
||||
if (size() == 0) return;
|
||||
std::memset(buf(), 0x00, std::size_t(num_words() * 4));
|
||||
}
|
||||
|
||||
// make the bitfield empty, of zero size.
|
||||
void clear() { m_buf.reset(); }
|
||||
void clear() noexcept { m_buf.reset(); }
|
||||
|
||||
private:
|
||||
|
||||
std::uint32_t const* buf() const { TORRENT_ASSERT(m_buf); return &m_buf[1]; }
|
||||
std::uint32_t* buf() { TORRENT_ASSERT(m_buf); return &m_buf[1]; }
|
||||
void clear_trailing_bits()
|
||||
std::uint32_t const* buf() const noexcept { TORRENT_ASSERT(m_buf); return &m_buf[1]; }
|
||||
std::uint32_t* buf() noexcept { TORRENT_ASSERT(m_buf); return &m_buf[1]; }
|
||||
void clear_trailing_bits() noexcept
|
||||
{
|
||||
// clear the tail bits in the last byte
|
||||
if (size() & 31) buf()[num_words() - 1] &= aux::host_to_network(0xffffffff << (32 - (size() & 31)));
|
||||
|
|
|
@ -70,6 +70,9 @@ namespace libtorrent {
|
|||
static_assert(std::is_nothrow_move_constructible<add_torrent_params>::value
|
||||
, "should be nothrow move constructible");
|
||||
|
||||
static_assert(std::is_nothrow_move_constructible<std::string>::value
|
||||
, "should be nothrow move constructible");
|
||||
|
||||
// TODO: pre C++17, GCC and msvc does not make std::string nothrow move
|
||||
// assignable, which means no type containing a string will be nothrow move
|
||||
// assignable by default either
|
||||
|
|
Loading…
Reference in New Issue