Back to home page

EIC code displayed by LXR

 
 

    


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

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 relation/detail/mutant.hpp
0010 /// \brief Mutate functions to extract views of mutant classes.
0011 
0012 #ifndef BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
0013 #define BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/config.hpp>
0020 
0021 #include <boost/bimap/detail/debug/static_error.hpp>
0022 #include <boost/mpl/contains.hpp>
0023 #include <boost/mpl/assert.hpp>
0024 #include <boost/static_assert.hpp>
0025 #include <boost/type_traits/is_const.hpp>
0026 #include <boost/utility/addressof.hpp>
0027 #include <boost/mpl/not.hpp>
0028 #include <boost/core/enable_if.hpp>
0029 
0030 namespace boost {
0031 namespace bimaps {
0032 namespace relation {
0033 
0034 /// \brief Relation details, mutant idiom and symmetrical metafunctions builders.
0035 
0036 namespace detail {
0037 
0038 //@{
0039 /// \brief Converts a mutant class to a view with zero overhead.
0040 /**
0041 
0042 This function is a safe wrapper around reinterpret_cast. It checks at
0043 compile time that the desired view is supported by the mutant class.
0044 See also mutant, can_mutate_in.
0045 \ingroup mutant_group
0046                                                                             **/
0047 
0048 
0049 template< class View, class Type >
0050 BOOST_DEDUCED_TYPENAME enable_if< mpl::not_< is_const< Type > >,
0051 
0052 View&
0053 
0054 >::type mutate( Type & m )
0055 {
0056     BOOST_MPL_ASSERT((
0057         ::boost::mpl::contains<BOOST_DEDUCED_TYPENAME Type::mutant_views,View>
0058     ));
0059     return *reinterpret_cast< View* >(boost::addressof(m));
0060 }
0061 
0062 template< class View, class Type >
0063 BOOST_DEDUCED_TYPENAME enable_if< is_const< Type >,
0064 
0065 const View&
0066 
0067 >::type mutate( Type & m )
0068 {
0069     BOOST_MPL_ASSERT((
0070         ::boost::mpl::contains<BOOST_DEDUCED_TYPENAME Type::mutant_views,View> 
0071     ));
0072     return *reinterpret_cast< const View* >(boost::addressof(m));
0073 }
0074 
0075 //@}
0076 
0077 } // namespace detail
0078 } // namespace relation
0079 } // namespace bimaps
0080 } // namespace boost
0081 
0082 #endif // BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
0083