Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:52

0001 /* Copyright 2006-2015 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/flyweight for library home page.
0007  */
0008 
0009 #ifndef BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
0010 #define BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/flyweight/assoc_container_factory_fwd.hpp>
0018 #include <boost/flyweight/detail/is_placeholder_expr.hpp>
0019 #include <boost/flyweight/detail/nested_xxx_if_not_ph.hpp>
0020 #include <boost/flyweight/factory_tag.hpp>
0021 #include <boost/mpl/apply.hpp>
0022 #include <boost/mpl/aux_/lambda_support.hpp>
0023 #include <boost/mpl/if.hpp>
0024 
0025 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0026 #include <utility>
0027 #endif
0028 
0029 namespace boost{namespace flyweights{namespace detail{
0030 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(iterator)
0031 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(value_type)
0032 }}} /* namespace boost::flyweights::detail */
0033 
0034 /* Factory class using a given associative container.
0035  */
0036 
0037 namespace boost{
0038 
0039 namespace flyweights{
0040 
0041 template<typename Container>
0042 class assoc_container_factory_class:public factory_marker
0043 {
0044 public:
0045   /* When assoc_container_factory_class<Container> is an MPL placeholder
0046    * expression, referring to Container::iterator and Container::value_type
0047    * force the MPL placeholder expression Container to be instantiated, which
0048    * is wasteful and can fail in concept-checked STL implementations.
0049    * We protect ourselves against this circumstance.
0050    */
0051 
0052   typedef typename detail::nested_iterator_if_not_placeholder_expression<
0053     Container
0054   >::type                                handle_type;
0055   typedef typename detail::nested_value_type_if_not_placeholder_expression<
0056     Container
0057   >::type                                entry_type;
0058   
0059   handle_type insert(const entry_type& x)
0060   {
0061     return cont.insert(x).first;
0062   }
0063 
0064 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0065   handle_type insert(entry_type&& x)
0066   {
0067     return cont.insert(std::move(x)).first;
0068   }
0069 #endif
0070 
0071   void erase(handle_type h)
0072   {
0073     cont.erase(h);
0074   }
0075 
0076   static const entry_type& entry(handle_type h){return *h;}
0077 
0078 private:
0079   /* As above, avoid instantiating Container if it is an
0080    * MPL placeholder expression.
0081    */
0082 
0083   typedef typename mpl::if_<
0084     detail::is_placeholder_expression<Container>,
0085     int,
0086     Container
0087   >::type container_type;
0088   container_type cont;
0089 
0090 public:
0091   typedef assoc_container_factory_class type;
0092   BOOST_MPL_AUX_LAMBDA_SUPPORT(1,assoc_container_factory_class,(Container))
0093 };
0094 
0095 /* assoc_container_factory_class specifier */
0096 
0097 template<
0098   typename ContainerSpecifier
0099   BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION_DEF
0100 >
0101 struct assoc_container_factory:factory_marker
0102 {
0103   template<typename Entry,typename Key>
0104   struct apply
0105   {
0106     typedef assoc_container_factory_class<
0107       typename mpl::apply2<ContainerSpecifier,Entry,Key>::type
0108     > type;
0109   };
0110 };
0111 
0112 }  /* namespace flyweights */
0113 
0114 } /* namespace boost */
0115 
0116 #endif