]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/poly_collection/example/basic_any.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 /* basic usage of boost::any_collection */
11 #include <boost/poly_collection/any_collection.hpp>
12 #include <boost/type_erasure/operators.hpp>
14 #include "rolegame.hpp"
17 std::ostream
& operator<<(std::ostream
& os
,const sprite
& s
)
23 // std::string already has a suitable operator<<
25 std::ostream
& operator<<(std::ostream
& os
,const window
& w
)
35 //= #include <boost/poly_collection/any_collection.hpp>
36 //= #include <boost/type_erasure/operators.hpp>
39 using renderable
=boost::type_erasure::ostreamable
<>;
40 boost::any_collection
<renderable
> c
;
44 // populate with sprites
45 std::mt19937 gen
{92748}; // some arbitrary random seed
46 std::discrete_distribution
<> rnd
{{1,1,1}};
47 for(int i
=0;i
<4;++i
){ // assign each type with 1/3 probability
49 case 0: c
.insert(warrior
{i
});break;
50 case 1: c
.insert(juggernaut
{i
});break;
51 case 2: c
.insert(goblin
{i
});break;
55 // populate with messages
56 c
.insert(std::string
{"\"stamina: 10,000\""});
57 c
.insert(std::string
{"\"game over\""});
59 // populate with windows
60 c
.insert(window
{"pop-up 1"});
61 c
.insert(window
{"pop-up 2"});