implement template foreach else and foreach=>as