1 // Copyright (c) 2001, Daniel C. Nuffer
2 // Copyright (c) 2001-2011 Hartmut Kaiser
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #if !defined(BOOST_SPIRIT_ITERATOR_FIRST_OWNER_POLICY_MAR_16_2007_1108AM)
8 #define BOOST_SPIRIT_ITERATOR_FIRST_OWNER_POLICY_MAR_16_2007_1108AM
10 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
11 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
13 namespace boost { namespace spirit { namespace iterator_policies
15 ///////////////////////////////////////////////////////////////////////////
17 // Implementation of an OwnershipPolicy used by multi_pass
18 // This ownership policy dictates that the first iterator created will
19 // determine the lifespan of the shared components. This works well for
20 // spirit, since no dynamic allocation of iterators is done, and all
21 // copies are make on the stack.
23 // There is a caveat about using this policy together with the std_deque
24 // StoragePolicy. Since first_owner always returns false from unique(),
25 // std_deque will only release the queued data if clear_queue() is called.
26 ///////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////
30 struct unique : detail::default_ownership_policy
32 unique() : first(true) {}
33 unique(unique const&) : first(false) {}
35 // return true to indicate deletion of resources
36 template <typename MultiPass>
37 static bool release(MultiPass& mp)
42 // use swap from default policy
43 // if we're the first, we still remain the first, even if assigned
44 // to, so don't swap first. swap is only called from operator=
46 template <typename MultiPass>
47 static bool is_unique(MultiPass const&)
49 return false; // no way to know, so always return false
56 ////////////////////////////////////////////////////////////////////////
57 struct shared {}; // no shared data
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams