Returning nullptr iterators, how to drop them

I have problems solving a problem in my program. Thus, at present, each piece returns an iterator, but the iterator depends on two cases:

the desired item is in the piece: the return resultIter; desired item was not found in the piece: 'return nullptr`

the first case is quite simple and easy to solve, but in the second case I ran into a problem. Given a template argument InIter, how can I convert nullptrto a category InIter?

template< typename InIter, ...>
InInter func(...) {
  InIter res = //returns iter to found element if found
    loop(...)  //if so a token will changed to signify a cancelation
  if(token.was_cancelled())
    return res; //easy enough
  return nullptr; //doesn't work
}

which gives me this error:

'nullptr': all returned expressions in lambda must be of the same type: earlier it was "test :: test_iterator"

, -, , . , , .

:

return InIter(nullptr);

return (InIter)(nullptr);

return NULL;

return InIter(NULL);

...

, . , , ?

+4
2

, , , , .

, :

InIter res = find_an_iterator_meeting_an_interesting_condition(begin, end);

, end. .

+9

.

-, , ( begin end).

- end.

(, , " Y?" " ", "-" ")

boost::optional - optional<Iterator>. nullopt, " ", , .

optional ++ ++ 14.

" " - std::pair<bool, Iterator>, .second, .first - false. boost, optional, .

+5

All Articles