mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 22:14:26 +02:00
Added constant static_vector<>/small_vector::static_capacity
to use the configured capacity in constant expressions.
This commit is contained in:
@@ -1220,8 +1220,10 @@ use [*Boost.Container]? There are several reasons for that:
|
|||||||
* [@https://svn.boost.org/trac/boost/ticket/12177 Trac #12177: ['"vector::priv_merge uses unqualified uintptr_t"]].
|
* [@https://svn.boost.org/trac/boost/ticket/12177 Trac #12177: ['"vector::priv_merge uses unqualified uintptr_t"]].
|
||||||
* [@https://svn.boost.org/trac/boost/ticket/12183 Trac #12183: ['"GCC 6.1 thinks boost::container::string violates strict aliasing"]].
|
* [@https://svn.boost.org/trac/boost/ticket/12183 Trac #12183: ['"GCC 6.1 thinks boost::container::string violates strict aliasing"]].
|
||||||
* [@https://svn.boost.org/trac/boost/ticket/12286 Trac #12286: ['"PMR flat_map from Boost Container does not compile"]].
|
* [@https://svn.boost.org/trac/boost/ticket/12286 Trac #12286: ['"PMR flat_map from Boost Container does not compile"]].
|
||||||
* [@https://svn.boost.org/trac/boost/ticket/12296 Trac #12296: ['"boost::container::{deque,string} combine for a memory leak"]].
|
* [@https://svn.boost.org/trac/boost/ticket/12296 Trac #12296: ['"{deque,string} combine for a memory leak"]].
|
||||||
* [@https://svn.boost.org/trac/boost/ticket/12319 Trac #12319: ['"boost::container::flat_set` should be nothrow move constructible"]].
|
* [@https://svn.boost.org/trac/boost/ticket/12319 Trac #12319: ['"flat_set` should be nothrow move constructible"]].
|
||||||
|
* [@https://svn.boost.org/trac/boost/ticket/12273 Trac #12273: ['"static_vector max_size() and capacity() should be constant expressions"]].
|
||||||
|
Added constant `static_vector<>::static_capacity` to use the configured capacity in constant expressions.
|
||||||
|
|
||||||
* Revised noexcept expressions of default and move constructors in all containers.
|
* Revised noexcept expressions of default and move constructors in all containers.
|
||||||
|
|
||||||
|
@@ -502,9 +502,12 @@ class small_vector : public small_vector_base<T, Allocator>
|
|||||||
|
|
||||||
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||||
|
|
||||||
|
//! @brief The capacity/max size of the container
|
||||||
|
static const size_type static_capacity = N;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BOOST_CONTAINER_FORCEINLINE small_vector()
|
BOOST_CONTAINER_FORCEINLINE small_vector()
|
||||||
BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
|
BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
|
||||||
: base_type(initial_capacity_t(), internal_capacity())
|
: base_type(initial_capacity_t(), internal_capacity())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@@ -139,6 +139,9 @@ public:
|
|||||||
//! @brief The const reverse iterator.
|
//! @brief The const reverse iterator.
|
||||||
typedef typename base_t::const_reverse_iterator const_reverse_iterator;
|
typedef typename base_t::const_reverse_iterator const_reverse_iterator;
|
||||||
|
|
||||||
|
//! @brief The capacity/max size of the container
|
||||||
|
static const size_type static_capacity = Capacity;
|
||||||
|
|
||||||
//! @brief Constructs an empty static_vector.
|
//! @brief Constructs an empty static_vector.
|
||||||
//!
|
//!
|
||||||
//! @par Throws
|
//! @par Throws
|
||||||
|
@@ -65,6 +65,7 @@ bool test_small_vector_base_test()
|
|||||||
typedef boost::container::small_vector_base<int> smb_t;
|
typedef boost::container::small_vector_base<int> smb_t;
|
||||||
{
|
{
|
||||||
typedef boost::container::small_vector<int, 5> sm5_t;
|
typedef boost::container::small_vector<int, 5> sm5_t;
|
||||||
|
BOOST_STATIC_ASSERT(sm5_t::static_capacity == 5);
|
||||||
sm5_t sm5;
|
sm5_t sm5;
|
||||||
smb_t &smb = sm5;
|
smb_t &smb = sm5;
|
||||||
smb.push_back(1);
|
smb.push_back(1);
|
||||||
@@ -75,6 +76,7 @@ bool test_small_vector_base_test()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef boost::container::small_vector<int, 7> sm7_t;
|
typedef boost::container::small_vector<int, 7> sm7_t;
|
||||||
|
BOOST_STATIC_ASSERT(sm7_t::static_capacity == 7);
|
||||||
sm7_t sm7;
|
sm7_t sm7;
|
||||||
smb_t &smb = sm7;
|
smb_t &smb = sm7;
|
||||||
smb.push_back(2);
|
smb.push_back(2);
|
||||||
|
@@ -33,6 +33,7 @@ template <typename T, size_t N>
|
|||||||
void test_ctor_ndc()
|
void test_ctor_ndc()
|
||||||
{
|
{
|
||||||
static_vector<T, N> s;
|
static_vector<T, N> s;
|
||||||
|
BOOST_STATIC_ASSERT((static_vector<T, N>::static_capacity) == N);
|
||||||
BOOST_TEST_EQ(s.size() , 0u);
|
BOOST_TEST_EQ(s.size() , 0u);
|
||||||
BOOST_TEST(s.capacity() == N);
|
BOOST_TEST(s.capacity() == N);
|
||||||
BOOST_TEST(s.max_size() == N);
|
BOOST_TEST(s.max_size() == N);
|
||||||
@@ -43,6 +44,7 @@ template <typename T, size_t N>
|
|||||||
void test_ctor_nc(size_t n)
|
void test_ctor_nc(size_t n)
|
||||||
{
|
{
|
||||||
static_vector<T, N> s(n);
|
static_vector<T, N> s(n);
|
||||||
|
BOOST_STATIC_ASSERT((static_vector<T, N>::static_capacity) == N);
|
||||||
BOOST_TEST(s.size() == n);
|
BOOST_TEST(s.size() == n);
|
||||||
BOOST_TEST(s.capacity() == N);
|
BOOST_TEST(s.capacity() == N);
|
||||||
BOOST_TEST(s.max_size() == N);
|
BOOST_TEST(s.max_size() == N);
|
||||||
@@ -64,6 +66,7 @@ template <typename T, size_t N>
|
|||||||
void test_ctor_nd(size_t n, T const& v)
|
void test_ctor_nd(size_t n, T const& v)
|
||||||
{
|
{
|
||||||
static_vector<T, N> s(n, v);
|
static_vector<T, N> s(n, v);
|
||||||
|
BOOST_STATIC_ASSERT((static_vector<T, N>::static_capacity) == N);
|
||||||
BOOST_TEST(s.size() == n);
|
BOOST_TEST(s.size() == n);
|
||||||
BOOST_TEST(s.capacity() == N);
|
BOOST_TEST(s.capacity() == N);
|
||||||
BOOST_TEST_THROWS( s.at(n), std::out_of_range );
|
BOOST_TEST_THROWS( s.at(n), std::out_of_range );
|
||||||
|
Reference in New Issue
Block a user