3 // Copyright (c) 2006-2007 Matias Capeletto
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 /// \file container_adaptor/detail/functor_bag.hpp
10 /// \brief Defines a EBO optimizacion helper for functors.
12 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_FUNCTOR_BAG_HPP
13 #define BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_FUNCTOR_BAG_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
21 #if defined(BOOST_MSVC)
22 // This bogus warning will appear when add_const is applied to a
23 // const volatile reference because we can't detect const volatile
24 // references with MSVC6.
25 # pragma warning(push)
26 # pragma warning(disable:4181)
27 // warning C4181: qualifier applied to reference type ignored
30 #include <boost/mpl/placeholders.hpp>
32 #include <boost/type_traits/add_reference.hpp>
33 #include <boost/type_traits/is_base_of.hpp>
35 #include <boost/mpl/inherit_linearly.hpp>
36 #include <boost/mpl/inherit.hpp>
40 namespace container_adaptor {
43 /// \brief EBO optimizacion helper for functors
46 This class is a generalization of a helper class explained in an article by
48 See it at \link http://www.cantrip.org/emptyopt.html
51 template < class Data, class FunctorList >
52 struct data_with_functor_bag :
54 public mpl::inherit_linearly<
57 mpl::if_< is_base_of< mpl::_2, mpl::_1 >,
63 mpl::inherit< mpl::_1, mpl::_2 >
71 data_with_functor_bag() {}
73 data_with_functor_bag(BOOST_DEDUCED_TYPENAME add_reference<Data>::type d)
76 template< class Functor >
79 return *(static_cast<Functor*>(this));
82 template< class Functor >
83 const Functor& functor() const
85 return *(static_cast<Functor const *>(this));
90 } // namespace container_adaptor
94 #if defined(BOOST_MSVC)
98 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_FUNCTOR_BAG_HPP