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 relation/detail/mutant.hpp
10 /// \brief Mutate functions to extract views of mutant classes.
12 #ifndef BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
13 #define BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
19 #include <boost/config.hpp>
21 #include <boost/bimap/detail/debug/static_error.hpp>
22 #include <boost/mpl/contains.hpp>
23 #include <boost/mpl/assert.hpp>
24 #include <boost/utility.hpp>
25 #include <boost/static_assert.hpp>
26 #include <boost/type_traits/is_const.hpp>
27 #include <boost/mpl/not.hpp>
28 #include <boost/utility/enable_if.hpp>
34 /// \brief Relation details, mutant idiom and symmetrical metafunctions builders.
39 /// \brief Converts a mutant class to a view with zero overhead.
42 This function is a safe wrapper around reinterpret_cast. It checks at
43 compile time that the desired view is supported by the mutant class.
44 See also mutant, can_mutate_in.
49 template< class View, class Type >
50 BOOST_DEDUCED_TYPENAME enable_if< mpl::not_< is_const< Type > >,
54 >::type mutate( Type & m )
57 ::boost::mpl::contains<BOOST_DEDUCED_TYPENAME Type::mutant_views,View>
59 return *reinterpret_cast< View* >(addressof(m));
62 template< class View, class Type >
63 BOOST_DEDUCED_TYPENAME enable_if< is_const< Type >,
67 >::type mutate( Type & m )
70 ::boost::mpl::contains<BOOST_DEDUCED_TYPENAME Type::mutant_views,View>
72 return *reinterpret_cast< const View* >(addressof(m));
78 } // namespace relation
82 #endif // BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP