Re: [Boost-bugs] [Boost C++ Libraries] #10393: Add begin/end specialization for optional<T> type

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10393: Add begin/end specialization for optional<T> type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-04-13 17:00:38


#10393: Add begin/end specialization for optional<T> type
-------------------------------+---------------------------------------
  Reporter: khimru@… | Owner: fcacciola
      Type: Feature Requests | Status: new
 Milestone: Boost 1.57.0 | Component: optional
   Version: Boost 1.56.0 | Severity: Cosmetic
Resolution: | Keywords: optional, for, begin, end
-------------------------------+---------------------------------------

Comment (by rob.desbois@…):

 You'd still have to check that the optional is initialized before doing so
 though. A simpler fix is to use the optional's dereference operator (when
 the optional<T> is initialized):

 {{{#!cpp
   if (opt_container)
     for (auto&& element : *opt_container)
     {}
 }}}

 A really useful facility would be `begin()` & `end()`
 overloads/specializations that could return an empty sequence when the
 optional is uninitialized, enabling direct passing of the `optional<T>`
 object to the range-for *without checking that it's initialized*. Given
 that in many cases (including standard library components) there's no way
 to construct a non-singular iterator without an underlying container this
 might be tricky...though a transparent wrapping iterator might do the
 trick.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10393#comment:1>
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:18 UTC