Grid template

The logic is the same, but the API changes because of the template, and some code has been moved from implementation to header files.
As a side note though, I find it confusing to add headers in the `add_library()` call. I know it is here to support broken IDEs, but it sure does not facilitate interpretation...