You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/functional/equal_ptr.hpp
  3. *
  4. * Purpose: Definition of stlsoft::equal_ptr predicate class.
  5. *
  6. * Created: 7th November 2004
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2004-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file stlsoft/functional/equal_ptr.hpp
  40. *
  41. * \brief [C++ only] Definition of the stlsoft::equal_ptr predicate, which
  42. * uses attribute shims to generalise comparison of raw/smart pointers
  43. * (\ref group__library__functional "Functional" Library).
  44. */
  45. #ifndef STLSOFT_INCL_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR
  46. #define STLSOFT_INCL_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define STLSOFT_VER_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR_MAJOR 3
  49. # define STLSOFT_VER_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR_MINOR 0
  50. # define STLSOFT_VER_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR_REVISION 1
  51. # define STLSOFT_VER_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR_EDIT 23
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  57. # include <stlsoft/stlsoft.h>
  58. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  59. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ATTRIBUTE_HPP_GET_PTR
  60. # include <stlsoft/shims/attribute/get_ptr.hpp>
  61. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ATTRIBUTE_HPP_GET_PTR */
  62. #ifdef STLSOFT_CF_std_NAMESPACE
  63. # include <functional>
  64. #endif /* STLSOFT_CF_std_NAMESPACE */
  65. /* /////////////////////////////////////////////////////////////////////////
  66. * Namespace
  67. */
  68. #ifndef _STLSOFT_NO_NAMESPACE
  69. namespace stlsoft
  70. {
  71. #endif /* _STLSOFT_NO_NAMESPACE */
  72. /* /////////////////////////////////////////////////////////////////////////
  73. * Classes
  74. */
  75. /** \brief Predicate used to test the equivalence of pointers
  76. *
  77. * \ingroup group__library__functional
  78. *
  79. */
  80. template< ss_typename_param_k P
  81. , ss_typename_param_k A = P const&
  82. >
  83. // [[synesis:class:function-class:unary-predicate: equal_ptr]]
  84. struct equal_ptr
  85. #ifdef STLSOFT_CF_std_NAMESPACE
  86. : public stlsoft_ns_qual_std(unary_function)<A, ss_bool_t>
  87. #endif /* STLSOFT_CF_std_NAMESPACE */
  88. {
  89. public:
  90. equal_ptr(P t)
  91. : m_p(t)
  92. {}
  93. public:
  94. /// Returns true if the given instance's underlying pointer is
  95. /// equal to that of the contained pointer.
  96. ss_bool_t operator ()(A p) const
  97. {
  98. return stlsoft_ns_qual(get_ptr)(p) == stlsoft_ns_qual(get_ptr)(m_p);
  99. }
  100. private:
  101. P m_p;
  102. };
  103. /* ////////////////////////////////////////////////////////////////////// */
  104. #ifndef _STLSOFT_NO_NAMESPACE
  105. } // namespace stlsoft
  106. #endif /* _STLSOFT_NO_NAMESPACE */
  107. /* ////////////////////////////////////////////////////////////////////// */
  108. #endif /* !STLSOFT_INCL_STLSOFT_FUNCTIONAL_HPP_EQUAL_PTR */
  109. /* ///////////////////////////// end of file //////////////////////////// */