[SmartQueue] Use template to improve safety.