1

How does one implement templates in modern Fortran?

A procedure which does basically the same for integer, and real arguments. Do you need to implement it for each type separately or can you implement it once for a generic type T?

Currently I do that via preprocessor directives and I want to know if there are other/more elegant ways.

jack
  • 1,658
  • 1
  • 7
  • 18
  • 1
    Do you mean something like templating? Write once for all types? There is nothing in native Fortran. There are discussions for some future Fortran standard. – Vladimir F Героям слава Feb 06 '21 at 12:35
  • 1
    Yes, but generic programming is also *very* wide. It often means stuff very different from what you likely have in mind. That's why it must be specified further. Even Fortran 90 generics are generic programming. Various type classes in functional languages are generic programming. C-like operations on type-less memory (bytes) are generic programming. This template-like (e.g. Java generics) writing one function or one module once is just one of many very different types of generic programming. – Vladimir F Героям слава Feb 06 '21 at 13:40
  • @VladimirF The question now asks specifically for templates. Thank you. – jack Feb 06 '21 at 14:28

0 Answers0