]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/poly_collection/example/exceptions.cpp
1 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 /* Boost.PolyCollection exceptions */
13 #include <boost/poly_collection/base_collection.hpp>
15 #include "rolegame.hpp"
19 boost::base_collection
<sprite
> c
,c2
;
23 std::mt19937 gen
{92748}; // some arbitrary random seed
24 std::discrete_distribution
<> rnd
{{1,1,1}};
25 for(int i
=0;i
<8;++i
){ // assign each type with 1/3 probability
27 case 0: c
.insert(warrior
{i
});break;
28 case 1: c
.insert(juggernaut
{i
});break;
29 case 2: c
.insert(goblin
{i
});break;
33 auto render
=[](const boost::base_collection
<sprite
>& c
){
35 for(const sprite
& s
:c
){
46 c
.insert(elf
{0}); // no problem
49 c2
=c
; // throws boost::poly_collection::not_copy_constructible
51 }catch(boost::poly_collection::not_copy_constructible
&){}
55 c
.clear
<elf
>(); // get rid of non-copyable elfs
57 // check that the two are indeed equal
58 std::cout
<<(c
==c2
)<<"\n";
59 // throws boost::poly_collection::not_equality_comparable
61 }catch(boost::poly_collection::not_equality_comparable
&){}