more robust implementation for BOOST_RANGE_EXTRACT_OPTIONAL_TYPE