Skip to content

Commit

Permalink
fixed boost::variant_collection_of<>
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquintides committed Dec 30, 2024
1 parent fcd9ceb commit 0ec8e33
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 18 deletions.
5 changes: 3 additions & 2 deletions doc/reference.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions include/boost/poly_collection/detail/type_restitution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){}

Expand Down Expand Up @@ -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){}

Expand Down
25 changes: 13 additions & 12 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ project
;

test-suite "poly_collection" :
[ run test_algorithm.cpp test_algorithm1.cpp
test_algorithm2.cpp test_algorithm3.cpp
test_algorithm4.cpp test_algorithm_main.cpp ]
[ run test_capacity.cpp test_capacity_main.cpp ]
[ run test_comparison.cpp test_comparison_main.cpp ]
[ run test_construction.cpp test_construction_main.cpp ]
[ run test_emplacement.cpp test_emplacement_main.cpp ]
[ run test_erasure.cpp test_erasure_main.cpp ]
[ 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_registration.cpp test_registration_main.cpp ]
[ run test_algorithm.cpp test_algorithm1.cpp
test_algorithm2.cpp test_algorithm3.cpp
test_algorithm4.cpp test_algorithm_main.cpp ]
[ run test_capacity.cpp test_capacity_main.cpp ]
[ run test_comparison.cpp test_comparison_main.cpp ]
[ run test_construction.cpp test_construction_main.cpp ]
[ run test_emplacement.cpp test_emplacement_main.cpp ]
[ run test_erasure.cpp test_erasure_main.cpp ]
[ 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 ]
;
70 changes: 70 additions & 0 deletions test/test_null_variant_collection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* 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);

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 changes: 9 additions & 0 deletions test/test_null_variant_collection.hpp
Original file line number Diff line number Diff line change
@@ -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();
16 changes: 16 additions & 0 deletions test/test_null_variant_collection_main.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 0ec8e33

Please sign in to comment.