Added at(size_type)

This commit is contained in:
akr
2022-04-22 19:53:08 +08:00
committed by Jim King
parent abd6417090
commit b15fd0075f

View File

@@ -293,6 +293,8 @@ public:
dynamic_bitset& flip(size_type n, size_type len);
dynamic_bitset& flip(size_type n);
dynamic_bitset& flip();
bool at(size_type n) const;
reference at(size_type n);
bool test(size_type n) const;
bool test_set(size_type n, bool val = true);
bool all() const;
@@ -1114,6 +1116,25 @@ bool dynamic_bitset<Block, Allocator>::m_unchecked_test(size_type pos) const
return (m_bits[block_index(pos)] & bit_mask(pos)) != 0;
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::at(size_type pos) const
{
if (pos >= m_num_bits)
BOOST_THROW_EXCEPTION(std::out_of_range("boost::dynamic_bitset::at out_of_range"));
return (*this)[pos];
}
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::reference
dynamic_bitset<Block, Allocator>::at(size_type pos)
{
if (pos >= m_num_bits)
BOOST_THROW_EXCEPTION(std::out_of_range("boost::dynamic_bitset::at out_of_range"));
return (*this)[pos];
}
template <typename Block, typename Allocator>
bool dynamic_bitset<Block, Allocator>::test(size_type pos) const
{