mirror of
https://github.com/boostorg/poly_collection.git
synced 2026-01-19 16:32:14 +00:00
* added variant_collection
* added variant_collection
* avoided &* on null pointers
* made (non-public) fixed_variant ctor explicit
* tested higher-arity visit
* implemented visit<void>
* fixed {boost::variant2|std}::variant insertion
* fixed lookup issues with invoke_visit
* removed unneeded constexpr qualifiers
* s/typeid_/index
* reverted c6bc62f6d2 as Clang 5.0 didnt seem to like it
* reinstated c6bc62f6d2
* dropped -std=c++1z for Clang 5.0
* updated docs and examples
* added boost::poly_collection::visit_by_index
* typo
* explicit cted tuple in make_iota_tuple
* changed function name to see if it helps with mangling-related Clang 3.8 ICE
* rewritten make_iota_tuple to try to make Clang 3.8 happier
* added boost::variant_collection_of
99 lines
2.9 KiB
C++
99 lines
2.9 KiB
C++
/* Copyright 2016-2024 Joaquin M Lopez Munoz.
|
|
* 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)
|
|
*
|
|
* See http://www.boost.org/libs/poly_collection for library home page.
|
|
*/
|
|
|
|
#include "test_capacity.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <boost/core/lightweight_test.hpp>
|
|
#include "any_types.hpp"
|
|
#include "base_types.hpp"
|
|
#include "function_types.hpp"
|
|
#include "variant_types.hpp"
|
|
#include "test_utilities.hpp"
|
|
|
|
using namespace test_utilities;
|
|
|
|
template<typename PolyCollection,typename ValueFactory,typename... Types>
|
|
void test_capacity()
|
|
{
|
|
PolyCollection p;
|
|
const PolyCollection& cp=p;
|
|
ValueFactory v;
|
|
|
|
BOOST_TEST(cp.empty());
|
|
BOOST_TEST(cp.size()==0);
|
|
|
|
register_types<Types...>(p);
|
|
BOOST_TEST(cp.empty());
|
|
do_((BOOST_TEST(cp.empty(typeid_<Types>(cp))),0)...);
|
|
do_((BOOST_TEST(cp.template empty<Types>()),0)...);
|
|
BOOST_TEST(cp.size()==0);
|
|
do_((BOOST_TEST(cp.size(typeid_<Types>(cp))==0),0)...);
|
|
do_((BOOST_TEST(cp.template size<Types>()==0),0)...);
|
|
|
|
p.reserve(10);
|
|
do_((BOOST_TEST(cp.capacity(typeid_<Types>(cp))>=10),0)...);
|
|
do_((BOOST_TEST(
|
|
cp.template capacity<Types>()==cp.capacity(typeid_<Types>(cp))),0)...);
|
|
|
|
do_((p.reserve(typeid_<Types>(p),20),0)...);
|
|
do_((BOOST_TEST(cp.capacity(typeid_<Types>(cp))>=20),0)...);
|
|
|
|
do_((p.template reserve<Types>(30),0)...);
|
|
do_((BOOST_TEST(cp.template capacity<Types>()>=30),0)...);
|
|
|
|
fill<constraints<>,Types...>(p,v,30);
|
|
BOOST_TEST(cp.size()==30*sizeof...(Types));
|
|
do_((BOOST_TEST(cp.size(typeid_<Types>(cp))==30),0)...);
|
|
do_((BOOST_TEST(
|
|
cp.template size<Types>()==cp.size(typeid_<Types>(cp))),0)...);
|
|
|
|
auto min_capacity=[&]{
|
|
return (std::min)({cp.template capacity<Types>()...});
|
|
};
|
|
|
|
p.reserve(min_capacity()+1);
|
|
BOOST_TEST(cp.size()==30*sizeof...(Types));
|
|
|
|
auto c=min_capacity();
|
|
p.shrink_to_fit();
|
|
BOOST_TEST(c>=min_capacity());
|
|
c=min_capacity();
|
|
|
|
do_((p.erase(cp.template begin<Types>()),0)...);
|
|
BOOST_TEST(c==min_capacity());
|
|
|
|
do_((p.shrink_to_fit(typeid_<Types>(p)),0)...);
|
|
BOOST_TEST(c>=min_capacity());
|
|
c=min_capacity();
|
|
|
|
p.clear();
|
|
do_((p.template shrink_to_fit<Types>(),0)...);
|
|
BOOST_TEST(c>=min_capacity());
|
|
}
|
|
|
|
void test_capacity()
|
|
{
|
|
test_capacity<
|
|
any_types::collection,auto_increment,
|
|
any_types::t1,any_types::t2,any_types::t3,
|
|
any_types::t4,any_types::t5>();
|
|
test_capacity<
|
|
base_types::collection,auto_increment,
|
|
base_types::t1,base_types::t2,base_types::t3,
|
|
base_types::t4,base_types::t5>();
|
|
test_capacity<
|
|
function_types::collection,auto_increment,
|
|
function_types::t1,function_types::t2,function_types::t3,
|
|
function_types::t4,function_types::t5>();
|
|
test_capacity<
|
|
variant_types::collection,auto_increment,
|
|
variant_types::t1,variant_types::t2,variant_types::t3,
|
|
variant_types::t4,variant_types::t5>();
|
|
}
|