Check for first == last before dereferencing first

Trac ticket [#6955](https://svn.boost.org/trac/boost/ticket/6955) describes an issue with dereferencing the past-the-end iterator in `parse_nan`. For details see https://svn.boost.org/trac/boost/ticket/6955. This pull request fixes this issue by checking `first != last` before dereferencing the `first` iterator.