Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:37

0001 // Boost.Bimap
0002 //
0003 // Copyright (c) 2006-2007 Matias Capeletto
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 /// \file container_adaptor/detail/functor_bag.hpp
0010 /// \brief Defines a EBO optimizacion helper for functors.
0011 
0012 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_FUNCTOR_BAG_HPP
0013 #define BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_FUNCTOR_BAG_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/config.hpp>
0020 
0021 #if defined(BOOST_MSVC)
0022 // This bogus warning will appear when add_const is applied to a
0023 // const volatile reference because we can't detect const volatile
0024 // references with MSVC6.
0025 #   pragma warning(push)
0026 #   pragma warning(disable:4181)
0027 // warning C4181: qualifier applied to reference type ignored
0028 #endif
0029 
0030 #include <boost/mpl/placeholders.hpp>
0031 
0032 #include <boost/type_traits/add_reference.hpp>
0033 #include <boost/type_traits/is_base_of.hpp>
0034 
0035 #include <boost/mpl/inherit_linearly.hpp>
0036 #include <boost/mpl/inherit.hpp>
0037 
0038 namespace boost {
0039 namespace bimaps {
0040 namespace container_adaptor {
0041 namespace detail {
0042 
0043 /// \brief EBO optimizacion helper for functors
0044 /**
0045 
0046 This class is a generalization of a helper class explained in an article by
0047 Nathan C. Myers.\n
0048 See it at \link http://www.cantrip.org/emptyopt.html
0049                                                                                     **/
0050 
0051 template < class Data, class FunctorList >
0052 struct data_with_functor_bag :
0053 
0054     public mpl::inherit_linearly<
0055 
0056         FunctorList,
0057         mpl::if_< is_base_of< mpl::_2, mpl::_1 >,
0058         //   {
0059                  mpl::_1,
0060         //   }
0061         //   else
0062         //   {
0063                  mpl::inherit< mpl::_1, mpl::_2 >
0064         //   }
0065         >
0066 
0067     >::type
0068 {
0069     Data data;
0070 
0071     data_with_functor_bag() {}
0072 
0073     data_with_functor_bag(BOOST_DEDUCED_TYPENAME add_reference<Data>::type d)
0074         : data(d) {}
0075 
0076     template< class Functor >
0077     Functor& functor()
0078     {
0079         return *(static_cast<Functor*>(this));
0080     }
0081 
0082     template< class Functor >
0083     const Functor& functor() const
0084     {
0085         return *(static_cast<Functor const *>(this));
0086     }
0087 };
0088 
0089 } // namespace detail
0090 } // namespace container_adaptor
0091 } // namespace bimaps
0092 } // namespace boost
0093 
0094 #if defined(BOOST_MSVC)
0095 #   pragma warning(pop)
0096 #endif
0097 
0098 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_FUNCTOR_BAG_HPP
0099 
0100