After reading this article Storing C++ template function definitions in a .CPP file, I know that the definition of a class that uses template has to be written in the header file in some way. So a client user can use it by importing the header files. Doesn't this mean the complete implementation details are revealed to the user? Does this also mean a library written with template must be provided in an open-source way?
Thanks for helping clarify it.
The details of the template implementation will be visible. You can provide explicit template instantiations if you know which parameters will be necessary, however. But to be a generic solution, you have to provide the implementation so it can be used with other parameters.
No, you don't have to release it as open source. Just because someone can see the code, doesn't mean it has to be open source. You can license it almost however you want, and the purchaser has to abide by those rules. After all, just because we can see the entire text of a novel doesn't mean we can do whatever we want with it.