Genericity has the advantage of being reusable. However, write things generic, only if:
- It doesn't take much more time to do that, than do it non-generic
- It doesn't complicate the code more than a non-generic solution
- You know will benefit from it later
However, know your standard library. The case you presented is already in STL as std::swap
.
Also, remember that when writing generically using templates, you can optimize special cases by using template specialization. However, always to it when it's needed for performance, not as you write it.
Also, note that you have the question of run-time and compile-time performance here. Template-based solutions increase compile-time. Inline solutions can but not must decrease run-time.
`Cause "Premature optimization and genericity is the root of all evil". And you can quote me on that -_-.