The bitset example mentioned would use the length specifier. A second example in connection with the k-D trees or radial basis function interpolation would be to use the length specifier for the problem dimensionality
type(rbf_interpolant(dp,3)) :: rbf3d
type(rbf_interpolant(dp,2)) :: rbf2d
real(dp) :: p(3), y3d, y2d
! ... initialize RBF interpolant ...
! evaluate RBF at Cartesian point p
y3d = rbf3d%eval(p)
y2d = rbf2d%eval(p) ! generate compiler error, size(p) /= 2
Concerning expression templates I am sure there are situations where they would be welcome in Fortran. The naive example on Wikipedia shows expression templates used for implementing delayed evaluation of a vector class, something that is best compared to the Fortran array syntax res = a + b + c
which is available straight out of the box.
On the other hand C++ users are forced to pick between several libraries with slightly different API’s:
If you decide to rely to tightly on any of them, it can be very challenging down the road to switch to a different one. I recall reading about linear algebra codes using expression templates beating LAPACK for small matrix sizes. Ideally, we would see similar optimization performed by the Fortran compilers.
Interestingly, the POOMA home page (dating to 1999) contains a few paragraphs on Fortran:
In fact, the combination of C++ and POOMA provides so many of the features of Fortran 90 that one might well ask whether it wouldn’t better to just use the latter language.
The simple answer is that the abstraction facilities of C++ are much more powerful than those in Fortran. A more powerful answer is economics. While the various flavors of Fortran are still the lingua franca of scientific computing, Fortran’s user base is shrinking, particularly in comparison to C++. Networking, graphics, database access, and operating system interfaces are available to C++ programmers long before they’re available in Fortran (if they become available at all). What’s more, support tools such as debuggers and memory inspectors are primarily targeted at C++ developers, as are hundreds of books, journal articles, and web sites.
Until recently, Fortran has had two powerful arguments in its favor: legacy applications and performance. However, the importance of the former is diminishing as the invention of new algorithms force programmers to rewrite old codes, while the invention of techniques such as expression templates has made it possible for C++ programs to match, or exceed, the performance of highly optimized Fortran 77.
Quite interestingly, there are proposals for C++23 to include a standard set of linear algebra templates in the standard library, see the documents
A proposal to add linear algebra support to the C++ standard library
There are several other interesting proposals of relevance for scientific computing in the C++ community, including differentiable programming, BLAS interface, statistical functions, graph library and also special functions (already accepted).