2

I am programming in Fortran 90. I am looking for a way to template my functions in fortran, similar to that of C++ templating. For example, in C++ one can write a function that takes in a variable that can be of some generic type rather than having to write individual functions for each individual type.

The only similar way that I've found to "somewhat" do this in Fortran 90 is through 'interface', but this requires each individual function for each type to be coded and then the individual functions are wrapped into some 'generic' interface. This is not very elegant as all my functions are the same, just that it takes in different types of arguments. Does anyone know of another way to do this in Fortran 90?

lawson123
  • 21
  • 2
  • Just found something similar on Google https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/594940 and it doesn't seem what I'm looking for is possible in Fortran – lawson123 Dec 22 '17 at 06:14
  • Have you searched before asking? This was diskussed several times. It is not worth repeating everything here. – Vladimir F Героям слава Dec 22 '17 at 06:41
  • Duplicates: https://stackoverflow.com/questions/24064633/how-to-make-some-generic-programming-in-fortran-90-95-working-with-intrinsic-typ https://stackoverflow.com/questions/23706742/template-in-fortran/23707004 https://stackoverflow.com/questions/24979199/stl-analogue-in-fortran https://stackoverflow.com/questions/12906127/simple-way-to-implement-a-group-of-queues-in-fortran https://stackoverflow.com/questions/27608610/fortran-subroutine-array-of-arbitrary-type https://stackoverflow.com/questions/29344251/fortran-handling-types-with-different-kind-in-generic-procedures yes, a lot of them... – Vladimir F Героям слава Dec 22 '17 at 06:55
  • The answer to your question is NO, there are no templates in Fortran. It is a frequently requested feature and there are several more or less complicated ways to emmulate them. See the links above. – Vladimir F Героям слава Dec 22 '17 at 07:48

0 Answers0