]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/example/container_actor.cpp
1 /*==============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2010 Thomas Heller
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
9 #include <boost/phoenix/core.hpp>
10 #include <boost/phoenix/function.hpp>
11 #include <boost/phoenix/stl/container.hpp>
12 #include <boost/phoenix/stl/algorithm.hpp>
18 namespace phoenix
= boost::phoenix
;
21 using phoenix::function
;
22 using phoenix::arg_names::arg1
;
26 // result_of protocol:
27 template <typename Sig
>
30 template <typename This
, typename Container
>
31 struct result
<This(Container
)>
33 // Note, remove reference here, because Container can be anything
34 typedef typename
boost::remove_reference
<Container
>::type container_type
;
36 // The result will be size_type
37 typedef typename
container_type::size_type type
;
40 template <typename Container
>
41 typename result
<size_impl(Container
const&)>::type
42 operator()(Container
const& container
) const
44 return container
.size();
48 template <typename Expr
>
49 struct container_actor
52 typedef actor
<Expr
> base_type
;
53 typedef container_actor
<Expr
> that_type
;
55 container_actor( base_type
const& base
= base_type() )
56 : base_type( base
) {}
58 typename
phoenix::expression::function
<phoenix::stl::begin
, that_type
>::type
const
61 return phoenix::begin(*this);
64 typename
phoenix::expression::function
<phoenix::stl::end
, that_type
>::type
const
67 return phoenix::end(*this);
70 typename
phoenix::expression::function
<size_impl
, that_type
>::type
const
73 function
<size_impl
> const f
= size_impl();
77 typename
phoenix::expression::function
<phoenix::stl::max_size
, that_type
>::type
const
80 return phoenix::max_size(*this);
83 typename
phoenix::expression::function
<phoenix::stl::empty
, that_type
>::type
const
86 return phoenix::empty(*this);
89 template <typename Container
>
90 typename
phoenix::expression::function
<phoenix::impl::swap
, that_type
, Container
>::type
const
91 swap(actor
<Container
> const& expr
) const
93 return phoenix::swap(*this, expr
);
97 template <typename Expr
>
98 container_actor
<Expr
> const
99 container( actor
<Expr
> const& expr
)
106 container_actor
<phoenix::expression::argument
<1>::type
> const con1
;
113 std::cout
<< (container(arg1
).size())(v
) << " == " << v
.size() << "\n";
116 std::cout
<< (con1
.size())(v
) << " == " << v
.size() << "\n";