Fix/null variant_collection (#27)

* fixed boost::variant_collection_of<>

* added tests for ==/!=
This commit is contained in:
joaquintides
2024-12-30 18:36:03 +01:00
committed by GitHub
parent fcd9cebc92
commit f3df1cdd21
7 changed files with 119 additions and 19 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ local library = "poly_collection";
local triggers =
{
branch: [ "master", "develop", "feature/*" ]
branch: [ "master", "develop", "feature/*", "fix/*" ]
};
local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' };
+3 -2
View File
@@ -1876,7 +1876,8 @@ For the description of the algorithms we use the following notation:
of a collection of Boost.PolyCollection such that \[`first`, `middle`) and
\[`middle`, `last`) are valid ranges.
* `args...` is a function parameter pack of types `Args&&...`,
* `Ts...` is a template parameter pack of arbitrary types.
* `Ts...` is a template parameter pack of acceptable types for the collection,
plus optionally `all_types` in the case of closed collections.
* Open collections: `Us...` is defined as `Ts...`.
* Closed collections: `Us...` is defined as the set of all acceptable types
in the collection if `all_types` is in `Ts...`, or as `Ts...` otherwise.
@@ -1917,7 +1918,7 @@ value, which disallows this type of polymorphism.].[br]
[*Effects:] Equivalent to `expr`.[br]
[*Returns:] `expr`.[br]
[*Complexity:] That of `expr`.[br]
[*Note:] In the case of closed collections, if `Us...` contains all the
[*Note:] In the case of closed collections, if `Us...` is not empty and contains all the
acceptable types of the collection (/total restitution/), then
the dereference operation of `rfirst`, `rmiddle` and `rlast` to the
collection's `value_type` is not ever instantiated.
@@ -177,8 +177,8 @@ struct restitute_range_class<std::true_type /* total */,F,T>
F f;
};
template<typename F>
struct restitute_range_class<std::false_type /* non total */,F>
template<typename IsTotal,typename F>
struct restitute_range_class<IsTotal,F>
{
restitute_range_class(const F& f):f(f){}
@@ -266,8 +266,8 @@ struct restitute_iterator_class<std::true_type /* total */,F,T>
F f;
};
template<typename F>
struct restitute_iterator_class<std::false_type /* non total */,F>
template<typename IsTotal,typename F>
struct restitute_iterator_class<IsTotal,F>
{
restitute_iterator_class(const F& f):f(f){}
+1
View File
@@ -35,5 +35,6 @@ test-suite "poly_collection" :
[ run test_fixed_variant.cpp test_fixed_variant_main.cpp ]
[ run test_insertion.cpp test_insertion_main.cpp ]
[ run test_iterators.cpp test_iterators_main.cpp ]
[ run test_null_variant_collection.cpp test_null_variant_collection_main.cpp ]
[ run test_registration.cpp test_registration_main.cpp ]
;
+73
View File
@@ -0,0 +1,73 @@
/* Copyright 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_null_variant_collection.hpp"
#include <boost/core/lightweight_test.hpp>
#include <boost/poly_collection/variant_collection.hpp>
#include <boost/poly_collection/algorithm.hpp>
#include <utility>
#include "test_utilities.hpp"
using namespace test_utilities;
void test_null_variant_collection()
{
using boost::poly_collection::unregistered_type;
using collection_type=boost::variant_collection_of<>;
using value_type=collection_type::value_type;
collection_type c,c2{c},c3{std::move(c2)};
const collection_type& cc=c;
c2=c;
c=std::move(c2);
(void)c.get_allocator();
(void)c.begin();
(void)c.end();
(void)c.cbegin();
(void)c.cend();
check_throw<unregistered_type>(
[&]{(void)c.begin(0);},
[&]{(void)c.end(0);},
[&]{(void)c.cbegin(0);},
[&]{(void)c.cend(0);});
check_throw<unregistered_type>(
[&]{c.segment(0);},
[&]{cc.segment(0);});
for(auto seg:c.segment_traversal()){(void)seg;}
for(auto seg:cc.segment_traversal()){(void)seg;}
BOOST_TEST(cc.empty());
check_throw<unregistered_type>([&]{(void)cc.empty(0);});
BOOST_TEST_EQ(cc.size(),0);
check_throw<unregistered_type>([&]{(void)cc.size(0);});
check_throw<unregistered_type>([&]{(void)cc.capacity(0);});
c.shrink_to_fit();
check_throw<unregistered_type>([&]{(void)c.shrink_to_fit(0);});
c.clear();
check_throw<unregistered_type>([&]{(void)c.clear(0);});
c.swap(c);
BOOST_TEST(cc==cc);
BOOST_TEST(!(cc!=cc));
auto f=[](value_type&){};
boost::poly_collection::for_each(c.begin(),c.end(),f);
boost::poly_collection::for_each_n(c.begin(),0,f);
}
+9
View File
@@ -0,0 +1,9 @@
/* Copyright 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.
*/
void test_null_variant_collection();
@@ -0,0 +1,16 @@
/* Copyright 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 <boost/core/lightweight_test.hpp>
#include "test_null_variant_collection.hpp"
int main()
{
test_null_variant_collection();
return boost::report_errors();
}