modifier_adaptor.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 detail/modifier_adaptor.hpp
  9. /// \brief A binary to unary functor relation modifier adaptor.
  10. #ifndef BOOST_BIMAP_DETAIL_MODIFIER_ADAPTOR_HPP
  11. #define BOOST_BIMAP_DETAIL_MODIFIER_ADAPTOR_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. namespace boost {
  17. namespace bimaps {
  18. namespace detail {
  19. /// \brief A binary to unary functor relation modifier adaptor.
  20. template
  21. <
  22. class Modifier,
  23. class NewArgument,
  24. class FirstExtractor,
  25. class SecondExtractor
  26. >
  27. struct relation_modifier_adaptor :
  28. Modifier,
  29. FirstExtractor,
  30. SecondExtractor
  31. {
  32. typedef NewArgument argument_type;
  33. typedef void result_type;
  34. relation_modifier_adaptor( const Modifier & m ) : Modifier(m) {}
  35. relation_modifier_adaptor( const Modifier & m,
  36. const FirstExtractor & fe,
  37. const SecondExtractor & se ) :
  38. Modifier(m), FirstExtractor(fe), SecondExtractor(se) {}
  39. void operator()( NewArgument & x ) const
  40. {
  41. Modifier::operator()(
  42. FirstExtractor ::operator()( x ),
  43. SecondExtractor::operator()( x )
  44. );
  45. }
  46. };
  47. /// \brief A simple unary modifier adaptor.
  48. // This modifier is equivalent to bind( Modifier, bind( Extractor, _1 ) )
  49. // It may be a good idea to start using Boost.Bind instead of it.
  50. template
  51. <
  52. class Modifier,
  53. class NewArgument,
  54. class Extractor
  55. >
  56. struct unary_modifier_adaptor :
  57. Modifier,
  58. Extractor
  59. {
  60. typedef NewArgument argument_type;
  61. typedef void result_type;
  62. unary_modifier_adaptor( const Modifier & m ) : Modifier(m) {}
  63. unary_modifier_adaptor( const Modifier & m,
  64. const Extractor & fe) :
  65. Modifier(m), Extractor(fe) {}
  66. void operator()( NewArgument & x ) const
  67. {
  68. Modifier::operator()( Extractor::operator()( x ) );
  69. }
  70. };
  71. } // namespace detail
  72. } // namespace bimap
  73. } // namespace boost
  74. #endif // BOOST_BIMAP_DETAIL_MODIFIER_ADAPTOR_HPP