Chris@16: // Boost.Bimap Chris@16: // Chris@16: // Copyright (c) 2006-2007 Matias Capeletto Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: /// \file relation/detail/mutant.hpp Chris@16: /// \brief Mutate functions to extract views of mutant classes. Chris@16: Chris@16: #ifndef BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP Chris@16: #define BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace bimaps { Chris@16: namespace relation { Chris@16: Chris@16: /// \brief Relation details, mutant idiom and symmetrical metafunctions builders. Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: //@{ Chris@16: /// \brief Converts a mutant class to a view with zero overhead. Chris@16: /** Chris@16: Chris@16: This function is a safe wrapper around reinterpret_cast. It checks at Chris@16: compile time that the desired view is supported by the mutant class. Chris@16: See also mutant, can_mutate_in. Chris@16: \ingroup mutant_group Chris@16: **/ Chris@16: Chris@16: Chris@16: template< class View, class Type > Chris@16: BOOST_DEDUCED_TYPENAME enable_if< mpl::not_< is_const< Type > >, Chris@16: Chris@16: View& Chris@16: Chris@16: >::type mutate( Type & m ) Chris@16: { Chris@16: BOOST_MPL_ASSERT(( Chris@16: ::boost::mpl::contains Chris@16: )); Chris@16: return *reinterpret_cast< View* >(boost::addressof(m)); Chris@16: } Chris@16: Chris@16: template< class View, class Type > Chris@16: BOOST_DEDUCED_TYPENAME enable_if< is_const< Type >, Chris@16: Chris@16: const View& Chris@16: Chris@16: >::type mutate( Type & m ) Chris@16: { Chris@16: BOOST_MPL_ASSERT(( Chris@16: ::boost::mpl::contains Chris@16: )); Chris@16: return *reinterpret_cast< const View* >(boost::addressof(m)); Chris@16: } Chris@16: Chris@16: //@} Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace relation Chris@16: } // namespace bimaps Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP Chris@16: