Content deleted Content added
A.Deira.born (talk | contribs) added references section |
|||
(10 intermediate revisions by 8 users not shown) | |||
Line 1:
{{More citation needed|date=February 2025}}
In [[computer programming]], '''rank''' with no further specifications is usually a synonym for (or refers to) "number of dimensions"; thus, for instance, a bi-dimensional array has rank ''two'', a three-dimensional array has rank ''three'' and so on.▼
Strictly, no formal definition can be provided which applies to every [[programming language]], since each of them has its own concepts, [[Formal semantics of programming languages | semantics]] and terminology; the term may not even be applicable or, to the contrary, applied with a very specific meaning in the context of a given language.▼
▲In [[computer programming]], '''rank''' with no further specifications is usually a synonym for (or refers to) "number of dimensions";<ref>{{Cite
In the case of [[APL programming language|APL]] the notion applies to every operand; and [[dyad|dyads]] ("binary functions") have a ''left rank'' and a ''right rank''.▼
▲Strictly, no formal definition can be provided which applies to every [[programming language]], since each of them has its own concepts, [[Formal semantics of programming languages
▲In the case of [[APL programming language|APL]] the notion applies to every operand; and [[
The box below instead shows how ''rank of a type'' and ''rank of an array expression'' could be defined (in a semi-formal style) for C++ and illustrates a simple way to calculate them at compile time.
<
#include <type_traits>
#include <cstddef>
Line 15 ⟶ 18:
* it is an array; zero otherwise (which is the usual convention)
*/
template <typename
{
};
template<typename
struct rank<
{
};
constexpr auto rank_v = rank<T>::value;
/* Rank of an expression
Line 26 ⟶ 36:
* Let the rank of an expression be the rank of its type
*/
▲template <typename t, std::size_t n>
template <typename T>
using unqualified_t = std::remove_cv_t<std::remove_reference_t<T>>;
template <typename T>
auto rankof(T&& expr)
{
return rank_v<unqualified_t<T>>;
}
</syntaxhighlight>
Given the code above the rank of a type T can be calculated at compile time by
:<
or the shorter form
and the rank of an array-expression ''expr'' by▼
:<source lang="cpp">sizeof(rankof(expr))</source>▼
:<syntaxhighlight lang="cpp">rank_v<T></syntaxhighlight>
==See also==
Line 43 ⟶ 63:
*[[Rank (J programming language)]], a concept of the same name in the [[J (programming language)|J programming language]]
== References ==
{{compu-lang-stub}}▼
<references />{{DEFAULTSORT:Rank (Computer Programming)}}
[[Category:Arrays]]
[[Category:Programming language topics]]
|