annotate DEPENDENCIES/generic/include/boost/flyweight/assoc_container_factory.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@101 1 /* Copyright 2006-2014 Joaquin M Lopez Munoz.
Chris@16 2 * Distributed under the Boost Software License, Version 1.0.
Chris@16 3 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 *
Chris@16 6 * See http://www.boost.org/libs/flyweight for library home page.
Chris@16 7 */
Chris@16 8
Chris@16 9 #ifndef BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
Chris@16 10 #define BOOST_FLYWEIGHT_ASSOC_CONTAINER_FACTORY_HPP
Chris@16 11
Chris@101 12 #if defined(_MSC_VER)
Chris@16 13 #pragma once
Chris@16 14 #endif
Chris@16 15
Chris@16 16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
Chris@16 17 #include <boost/flyweight/assoc_container_factory_fwd.hpp>
Chris@16 18 #include <boost/flyweight/detail/is_placeholder_expr.hpp>
Chris@16 19 #include <boost/flyweight/detail/nested_xxx_if_not_ph.hpp>
Chris@16 20 #include <boost/flyweight/factory_tag.hpp>
Chris@16 21 #include <boost/mpl/apply.hpp>
Chris@16 22 #include <boost/mpl/aux_/lambda_support.hpp>
Chris@16 23 #include <boost/mpl/if.hpp>
Chris@16 24
Chris@101 25 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Chris@101 26 #include <utility>
Chris@101 27 #endif
Chris@101 28
Chris@16 29 namespace boost{namespace flyweights{namespace detail{
Chris@16 30 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(iterator);
Chris@16 31 BOOST_FLYWEIGHT_NESTED_XXX_IF_NOT_PLACEHOLDER_EXPRESSION_DEF(value_type);
Chris@16 32 }}} /* namespace boost::flyweights::detail */
Chris@16 33
Chris@16 34 /* Factory class using a given associative container.
Chris@16 35 */
Chris@16 36
Chris@16 37 namespace boost{
Chris@16 38
Chris@16 39 namespace flyweights{
Chris@16 40
Chris@16 41 template<typename Container>
Chris@16 42 class assoc_container_factory_class:public factory_marker
Chris@16 43 {
Chris@16 44 public:
Chris@16 45 /* When assoc_container_factory_class<Container> is an MPL placeholder
Chris@16 46 * expression, referring to Container::iterator and Container::value_type
Chris@16 47 * force the MPL placeholder expression Container to be instantiated, which
Chris@16 48 * is wasteful and can fail in concept-checked STL implementations.
Chris@16 49 * We protect ourselves against this circumstance.
Chris@16 50 */
Chris@16 51
Chris@16 52 typedef typename detail::nested_iterator_if_not_placeholder_expression<
Chris@16 53 Container
Chris@16 54 >::type handle_type;
Chris@16 55 typedef typename detail::nested_value_type_if_not_placeholder_expression<
Chris@16 56 Container
Chris@16 57 >::type entry_type;
Chris@16 58
Chris@16 59 handle_type insert(const entry_type& x)
Chris@16 60 {
Chris@16 61 return cont.insert(x).first;
Chris@16 62 }
Chris@16 63
Chris@101 64 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Chris@101 65 handle_type insert(entry_type&& x)
Chris@101 66 {
Chris@101 67 return cont.insert(std::move(x)).first;
Chris@101 68 }
Chris@101 69 #endif
Chris@101 70
Chris@16 71 void erase(handle_type h)
Chris@16 72 {
Chris@16 73 cont.erase(h);
Chris@16 74 }
Chris@16 75
Chris@16 76 static const entry_type& entry(handle_type h){return *h;}
Chris@16 77
Chris@16 78 private:
Chris@16 79 /* As above, avoid instantiating Container if it is an
Chris@16 80 * MPL placeholder expression.
Chris@16 81 */
Chris@16 82
Chris@16 83 typedef typename mpl::if_<
Chris@16 84 detail::is_placeholder_expression<Container>,
Chris@16 85 int,
Chris@16 86 Container
Chris@16 87 >::type container_type;
Chris@16 88 container_type cont;
Chris@16 89
Chris@16 90 public:
Chris@16 91 typedef assoc_container_factory_class type;
Chris@16 92 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,assoc_container_factory_class,(Container))
Chris@16 93 };
Chris@16 94
Chris@16 95 /* assoc_container_factory_class specifier */
Chris@16 96
Chris@16 97 template<
Chris@16 98 typename ContainerSpecifier
Chris@16 99 BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION_DEF
Chris@16 100 >
Chris@16 101 struct assoc_container_factory:factory_marker
Chris@16 102 {
Chris@16 103 template<typename Entry,typename Key>
Chris@16 104 struct apply
Chris@16 105 {
Chris@16 106 typedef assoc_container_factory_class<
Chris@16 107 typename mpl::apply2<ContainerSpecifier,Entry,Key>::type
Chris@16 108 > type;
Chris@16 109 };
Chris@16 110 };
Chris@16 111
Chris@16 112 } /* namespace flyweights */
Chris@16 113
Chris@16 114 } /* namespace boost */
Chris@16 115
Chris@16 116 #endif