Re: [Boost-bugs] [Boost C++ Libraries] #5991: find_ptr (find wrapper)

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5991: find_ptr (find wrapper)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-11-03 15:02:05


#5991: find_ptr (find wrapper)
-------------------------------------------------------+--------------------
  Reporter: Olaf van der Spek <olafvdspek@…> | Owner: joaquin
      Type: Feature Requests | Status: closed
 Milestone: To Be Determined | Component: multi_index
   Version: Boost 1.47.0 | Severity: Problem
Resolution: wontfix | Keywords:
-------------------------------------------------------+--------------------

Comment (by Olaf van der Spek <olafvdspek@…>):

 Replying to [comment:6 joaquin]:
> Why a pointer to second?

 Because the key is known already.

> This is not consistent with the semantics of std::map, which returns an
 iterator to the whole element (the key-value pair), not the value alone.

 std::map doesn't have find_ptr().

> > IMO the wrapper is useful every time you use a map like container.
>
> In either case, find_ptr can be provided as an (overloaded) function, no
 need to have as a built-in member function. Thus my reluctance to address
 your request.

 Can it? I can't (easily) select another overload for containers (like
 multi_index) that don't have a pair value_type.

 My find_ptr() for std::map (and std::unordered_map, boost::ptr_map, etc):
 {{{
 template <class T, class U>
 typename T::value_type::second_type* find_ptr(T& c, U v)
 {
         typename T::iterator i = c.find(v);
         return i == c.end() ? NULL : &i->second;
 }

 template <class T, class U>
 const typename T::value_type::second_type* find_ptr(const T& c, U v)
 {
         typename T::const_iterator i = c.find(v);
         return i == c.end() ? NULL : &i->second;
 }

 template <class T, class U>
 typename T::value_type::second_type find_ptr2(T& c, U v)
 {
         typename T::iterator i = c.find(v);
         return i == c.end() ? NULL : i->second;
 }

 template <class T, class U>
 const typename T::value_type::second_type find_ptr2(const T& c, U v)
 {
         typename T::const_iterator i = c.find(v);
         return i == c.end() ? NULL : i->second;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5991#comment:7>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC