Fortran Arrays in C++

The lack of standard multi-dimensional arrays has been a long-standing problem for C and C++ programmers, forcing them to invent dozens of array and tensor containers. I assembled a list at some point:

C:

C++:

Each library caters to different use cases. Some are just array containers some offer extensive linear algebra (BLAS/LAPACK wrappers) and some even offer nice tensor syntax. There are downsides compared to built-in arrays:

  • you need to install and configure the library
  • if you write an algorithm tied to one array container, it ain’t directly reusable from other libraries (most libraries have a way to wrap an existing pointer)
  • some libraries make extensive use of template meta-programming, which can be hard to develop and leads to long compilation times

I think having a Fortran-inspired library like FAR is good place for Fortran programmers to start with modern C++ when they have reasons to do so.

It should also be easy to interoperate with existing Fortran code in case needed using the advanced interoperability features in Fortran 2018. I did an example of Eigen++ wrappers before: Weather and climate modeling codes from Fortran to C++ - #41 by ivanpribec

6 Likes