Re:Why physicists still use Fortran
by pbsd on Sunday December 18, 2016 @09:36PM
(#13209125)
Not to mention all of that array behavior is available on the standard C++ library with std::valarray<T>, e.g., https://godbolt.org/g/JBSvuH. There was talk of a more thorough standard multi-dimensional array type, but I have no idea what's the status on that.
[ Parent
| on HN ]
Gotta admit that array slicing syntax is still friendlier in Fortran
a = [1,2,3,4,5,6]
a(1:3) ! gives [1,2,3]
than with std::valarray a = {1,2,3,4,5,6};
a[slice(0,3,0)]; // gives {1,2,3}
And I couldn't even find examples on how to do slicing with multi-dimensional arrays in std::valarray?In Fortran it's just
a(1:3,1:3)std::valarray does not have multidimensional support at all. In fact, std::valarray is a relatively abandoned part of the standard library. You'll have to go with one of the 3rd party libraries for better support.
My point was not so much that valarray is awesome, but that articles like this one tend to fight a very strawman version of C++, even when just sticking to strictly standard components.
If anything, saying that C++ has no support for linear algebra is giving it too much credit. C++ has an abundance of libraries that are broken in various strange and marvelous ways. Typically, you find out about the brokenness only after you made the investment of learning the library and put it into production, so that there is no way back. Your comment about valarray is a good example of this.