And the first world war saw massed use of human wave attacks against heavily entrenched machine guns.
Just because the military leaders of the time are using it doesn't mean its still an effective or efficient method of fighting.

I am quite aware that machine guns were not present in Napoleonic times. However, bayonets were. Cavalry were limited to a very specialized role. As was mentioned, flanking and chasing a fleeing enemy, or fighting other cavalry.
Dragoons might be the exception, but they were regarded as rather the low end of cavalry.