matrix function template for triangular_matrix and matrix datatypes
Suppose we are working in namespace boost::numeric::ublas and I have 2 functions 1) template <class T> save_matrix(matrix<T> const &m) 2) template <class T> save_matrix(triangular_matrix<T,lower> const &m) and the code in both overloaded save_matrix functions is identical. How can I write a templated function which accepts any type of a matrix? I tried this, but it didn't work: template <class T> save_matrix(T const &m) Thanks, Max
Sorry for the spam, I didn't realize that C++ has a template problem. One possible resolution is to place the source inside the header file, which is what I did. There another resolution, which uses the "export" keyword and you can also place the template declaration at the end of the source file. Max On Mon, Aug 2, 2010 at 2:05 PM, Max S. Kaznady <max.kaznady@gmail.com> wrote:
Suppose we are working in namespace boost::numeric::ublas and I have 2 functions
1) template <class T> save_matrix(matrix<T> const &m) 2) template <class T> save_matrix(triangular_matrix<T,lower> const &m)
and the code in both overloaded save_matrix functions is identical. How can I write a templated function which accepts any type of a matrix? I tried this, but it didn't work: template <class T> save_matrix(T const &m)
Thanks, Max
On 08/02/10 17:52, Max S. Kaznady wrote: [snip]
There another resolution, which uses the "export" keyword and you can also place the template declaration at the end of the source file. [snip] Hi Max,
Based on recent threads with subject: Any hopes for export ? in both Newsgroups: comp.std.c++ comp.lang.c++.moderated I wouldn't depend on export being well supported. HTH. -Larry
Yeah, it isn't. Even adding the template definition at the end of the source file isn't supported well, at least by g++-4.4. So I ended up adding the code to the header file. Boost functors use the same solution, all code is inside the header, see here: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Examples_-_Ho... Max On Tue, Aug 3, 2010 at 5:52 AM, Larry Evans <cppljevans@suddenlink.net> wrote:
On 08/02/10 17:52, Max S. Kaznady wrote: [snip]
There another resolution, which uses the "export" keyword and you can also place the template declaration at the end of the source file.
[snip] Hi Max,
Based on recent threads with subject:
Any hopes for export ?
in both Newsgroups:
comp.std.c++ comp.lang.c++.moderated
I wouldn't depend on export being well supported.
HTH.
-Larry
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Larry Evans
-
Max S. Kaznady