]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/move/example/doc_move_return.cpp
1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-2014.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/move for documentation.
10 //////////////////////////////////////////////////////////////////////////////
12 #include <boost/move/detail/config_begin.hpp>
14 //[move_return_example
15 #include "movable.hpp"
16 #include "copymovable.hpp"
17 #include <boost/move/core.hpp>
20 struct factory_functor
22 typedef Type return_type
;
24 Type
operator()() const
25 { Type t
; return BOOST_MOVE_RET(Type
, t
); }
28 struct return_reference
30 typedef non_copy_movable
&return_type
;
32 non_copy_movable
&operator()() const
35 static non_copy_movable ncm
;
38 non_copy_movable
return_reference::ncm
;
40 //A wrapper that locks a mutex while the
41 //factory creates a new value.
42 //It must generically move the return value
43 //if possible both in C++03 and C++11
44 template <class Factory
>
45 typename
Factory::return_type
lock_wrapper(Factory f
)
47 typedef typename
Factory::return_type return_type
;
52 //In C++03: boost::move() if R is not a reference and
53 //has move emulation enabled. In C++11: just return r.
54 return BOOST_MOVE_RET(return_type
, r
);
59 movable m
= lock_wrapper(factory_functor
<movable
> ());
60 copy_movable cm
= lock_wrapper(factory_functor
<copy_movable
>());
61 copyable c
= lock_wrapper(factory_functor
<copyable
> ());
62 non_copy_movable
&mr
= lock_wrapper(return_reference ());
64 (void)m
; (void)cm
; (void)c
; (void)mr
;
70 #include <boost/move/detail/config_end.hpp>