A rearguard is a part of a military force that protects the main force from attack from the rear. This is either during an advance or withdrawal. The term can also be used to describe forces protecting lines of communication behind an army. In modern armies the rearguard may be used to delay an enemy, to keep supply routes open or may also gather intelligence on an enemy approaching from the rear. One of the best recorded examples of a rearguard action is found in The Song of Roland. It is based on the historical events of the attack on the rearguard of Charlemagne's army in the Pyrenees. It was written in the 11th century, three hundred years after it happened.