1 /* Copyright 2006-2014 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.
9 #ifndef BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
10 #define BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
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 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
29 namespace boost{namespace flyweights{namespace detail{
30 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(iterator);
31 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(value_type);
32 }}} /* namespace boost::flyweights::detail */
34 /* Factory class using a given associative container.
41 template<typename Container>
42 class assoc_container_factory_class:public factory_marker
45 /* When assoc_container_factory_class<Container> is an MPL placeholder
46 * expression, referring to Container::iterator and Container::value_type
47 * force the MPL placeholder expression Container to be instantiated, which
48 * is wasteful and can fail in concept-checked STL implementations.
49 * We protect ourselves against this circumstance.
52 typedef typename detail::nested_iterator_if_not_placeholder_expression<
55 typedef typename detail::nested_value_type_if_not_placeholder_expression<
59 handle_type insert(const entry_type& x)
61 return cont.insert(x).first;
64 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
65 handle_type insert(entry_type&& x)
67 return cont.insert(std::move(x)).first;
71 void erase(handle_type h)
76 static const entry_type& entry(handle_type h){return *h;}
79 /* As above, avoid instantiating Container if it is an
80 * MPL placeholder expression.
83 typedef typename mpl::if_<
84 detail::is_placeholder_expression<Container>,
87 >::type container_type;
91 typedef assoc_container_factory_class type;
92 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,assoc_container_factory_class,(Container))
95 /* assoc_container_factory_class specifier */
98 typename ContainerSpecifier
99 BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION_DEF
101 struct assoc_container_factory:factory_marker
103 template<typename Entry,typename Key>
106 typedef assoc_container_factory_class<
107 typename mpl::apply2<ContainerSpecifier,Entry,Key>::type
112 } /* namespace flyweights */
114 } /* namespace boost */