to_mutable_relation_functor.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /// \file relation/detail/to_mutable_relation_functor.hpp
  9. /// \brief functors to convert types to mutable relations
  10. #ifndef BOOST_BIMAP_RELATION_DETAIL_TO_MUTABLE_RELATION_FUNCTOR_HPP
  11. #define BOOST_BIMAP_RELATION_DETAIL_TO_MUTABLE_RELATION_FUNCTOR_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/bimap/relation/support/pair_type_by.hpp>
  17. #include <boost/bimap/relation/detail/mutant.hpp>
  18. #include <boost/bimap/relation/mutant_relation.hpp>
  19. namespace boost {
  20. namespace bimaps {
  21. namespace relation {
  22. namespace detail {
  23. /// \brief Functor used in map views
  24. template< class Tag, class Relation >
  25. struct pair_to_relation_functor
  26. {
  27. const Relation
  28. operator()(const BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
  29. pair_type_by<Tag,Relation>::type & p) const
  30. {
  31. return Relation(p);
  32. }
  33. };
  34. template< class Tag, class TA, class TB, class Info >
  35. struct pair_to_relation_functor<
  36. Tag,::boost::bimaps::relation::mutant_relation<TA,TB,Info,true> >
  37. {
  38. typedef ::boost::bimaps::relation::mutant_relation<TA,TB,Info,true> Relation;
  39. Relation &
  40. operator()( BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
  41. pair_type_by<Tag,Relation>::type & p ) const
  42. {
  43. return ::boost::bimaps::relation::detail::mutate<Relation>(p);
  44. }
  45. const Relation &
  46. operator()( const BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
  47. pair_type_by<Tag,Relation>::type & p) const
  48. {
  49. return ::boost::bimaps::relation::detail::mutate<Relation>(p);
  50. }
  51. };
  52. /// \brief Used in set views
  53. template< class Relation >
  54. struct get_mutable_relation_functor
  55. {
  56. const Relation
  57. operator()( const BOOST_DEDUCED_TYPENAME Relation::above_view & r ) const
  58. {
  59. return Relation(r);
  60. }
  61. };
  62. template< class TA, class TB, class Info >
  63. struct get_mutable_relation_functor< ::boost::bimaps::relation::mutant_relation<TA,TB,Info,true> >
  64. {
  65. typedef ::boost::bimaps::relation::mutant_relation<TA,TB,Info,true> Relation;
  66. Relation &
  67. operator()( BOOST_DEDUCED_TYPENAME Relation::above_view & r ) const
  68. {
  69. return ::boost::bimaps::relation::detail::mutate<Relation>(r);
  70. }
  71. const Relation &
  72. operator()( const BOOST_DEDUCED_TYPENAME Relation::above_view & r ) const
  73. {
  74. return ::boost::bimaps::relation::detail::mutate<Relation>(r);
  75. }
  76. };
  77. } // namespace detail
  78. } // namespace relation
  79. } // namespace bimaps
  80. } // namespace boost
  81. #endif // BOOST_BIMAP_RELATION_DETAIL_TO_MUTABLE_RELATION_FUNCTOR_HPP