]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/bimap/include/boost/bimap/relation/detail/mutant.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / bimap / include / boost / bimap / relation / detail / mutant.hpp
CommitLineData
7c673cae
FG
1// Boost.Bimap
2//
3// Copyright (c) 2006-2007 Matias Capeletto
4//
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)
8
9/// \file relation/detail/mutant.hpp
10/// \brief Mutate functions to extract views of mutant classes.
11
12#ifndef BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
13#define BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
14
15#if defined(_MSC_VER)
16#pragma once
17#endif
18
19#include <boost/config.hpp>
20
21#include <boost/bimap/detail/debug/static_error.hpp>
22#include <boost/mpl/contains.hpp>
23#include <boost/mpl/assert.hpp>
24#include <boost/static_assert.hpp>
25#include <boost/type_traits/is_const.hpp>
26#include <boost/utility/addressof.hpp>
27#include <boost/mpl/not.hpp>
28#include <boost/utility/enable_if.hpp>
29
30namespace boost {
31namespace bimaps {
32namespace relation {
33
34/// \brief Relation details, mutant idiom and symmetrical metafunctions builders.
35
36namespace detail {
37
38//@{
39/// \brief Converts a mutant class to a view with zero overhead.
40/**
41
42This function is a safe wrapper around reinterpret_cast. It checks at
43compile time that the desired view is supported by the mutant class.
44See also mutant, can_mutate_in.
45\ingroup mutant_group
46 **/
47
48
49template< class View, class Type >
50BOOST_DEDUCED_TYPENAME enable_if< mpl::not_< is_const< Type > >,
51
52View&
53
54>::type mutate( Type & m )
55{
56 BOOST_MPL_ASSERT((
57 ::boost::mpl::contains<BOOST_DEDUCED_TYPENAME Type::mutant_views,View>
58 ));
59 return *reinterpret_cast< View* >(boost::addressof(m));
60}
61
62template< class View, class Type >
63BOOST_DEDUCED_TYPENAME enable_if< is_const< Type >,
64
65const View&
66
67>::type mutate( Type & m )
68{
69 BOOST_MPL_ASSERT((
70 ::boost::mpl::contains<BOOST_DEDUCED_TYPENAME Type::mutant_views,View>
71 ));
72 return *reinterpret_cast< const View* >(boost::addressof(m));
73}
74
75//@}
76
77} // namespace detail
78} // namespace relation
79} // namespace bimaps
80} // namespace boost
81
82#endif // BOOST_BIMAP_RELATION_DETAIL_MUTANT_HPP
83