It is not straightforward to cast, for example, an std::vector<float>::iterator to a float pointer. The post here has a solution. But, consider the following situation:
struct vec3f{
float x,y,z;
};
std::vector<vec3f> vertices;
float *begin_ptr = vertices.begin(); // doesn't work
float *end_ptr = vertices.end(); // doesn't work
std::for_each(begin_ptr, end_ptr, do_something);
The pointers are going to be used in a combination with a reinterpret_cast<> and some algorithm. In this case data access will only be performed if begin_ptr != end_ptr. We can simply let:
float * begin_ptr = reinterpret_cast<float*>(&vertices[0]); // safe even for empty vectors
float * end_ptr = begin_ptr + (vertices.end() - vertices.begin())*3;
Which for an empty vector gives begin_ptr==end_ptr. It is a bit sketchy to rely on operator [] to not do any bounds checking, though. std::vector's doesn't, but other containers might.
