fix doc example typo
[boost.git] / boost / flyweight / assoc_container_factory.hpp
blobbb5ae76541ad419bf045ef470d16d713a357e613
1 /* Copyright 2006-2009 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/flyweight for library home page.
7 */
9 #ifndef BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
10 #define BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
13 #pragma once
14 #endif
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/flyweight/assoc_container_factory_fwd.hpp>
18 #include <boost/flyweight/detail/is_placeholder_expr.hpp>
19 #include <boost/flyweight/detail/nested_xxx_if_not_ph.hpp>
20 #include <boost/flyweight/factory_tag.hpp>
21 #include <boost/mpl/apply.hpp>
22 #include <boost/mpl/aux_/lambda_support.hpp>
23 #include <boost/mpl/if.hpp>
25 namespace boost{namespace flyweights{namespace detail{
26 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(iterator);
27 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(value_type);
28 }}} /* namespace boost::flyweights::detail */
30 /* Factory class using a given associative container.
33 namespace boost{
35 namespace flyweights{
37 template<typename Container>
38 class assoc_container_factory_class:public factory_marker
40 public:
41 /* When assoc_container_factory_class<Container> is an MPL placeholder
42 * expression, referring to Container::iterator and Container::value_type
43 * force the MPL placeholder expression Container to be instantiated, which
44 * is wasteful and can fail in concept-checked STL implementations.
45 * We protect ourselves against this circumstance.
48 typedef typename detail::nested_iterator_if_not_placeholder_expression<
49 Container
50 >::type handle_type;
51 typedef typename detail::nested_value_type_if_not_placeholder_expression<
52 Container
53 >::type entry_type;
55 handle_type insert(const entry_type& x)
57 return cont.insert(x).first;
60 void erase(handle_type h)
62 cont.erase(h);
65 static const entry_type& entry(handle_type h){return *h;}
67 private:
68 /* As above, avoid instantiating Container if it is an
69 * MPL placeholder expression.
72 typedef typename mpl::if_<
73 detail::is_placeholder_expression<Container>,
74 int,
75 Container
76 >::type container_type;
77 container_type cont;
79 public:
80 typedef assoc_container_factory_class type;
81 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,assoc_container_factory_class,(Container))
84 /* assoc_container_factory_class specifier */
86 template<
87 typename ContainerSpecifier
88 BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION_DEF
90 struct assoc_container_factory:factory_marker
92 template<typename Entry,typename Key>
93 struct apply
95 typedef assoc_container_factory_class<
96 typename mpl::apply2<ContainerSpecifier,Entry,Key>::type
97 > type;
101 } /* namespace flyweights */
103 } /* namespace boost */
105 #endif