Rank (computer programming): Difference between revisions

Content deleted Content added
Reformat code, add rank_v and fix rankof
added references section
 
(4 intermediate revisions by 2 users not shown)
Line 1:
{{UnreferencedMore citation needed|date=DecemberFebruary 20092025}}
 
In [[computer programming]], '''rank''' with no further specifications is usually a synonym for (or refers to) "number of dimensions";<ref>{{Cite web |title=Vocabulary_with_defintions |url=https://files.schudio.com/federation-of-boldmere-schools/files/documents/Vocabulary_with_defintions.docx}}</ref> thus, a two-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.
 
Line 7 ⟶ 8:
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.
 
<sourcesyntaxhighlight lang="cpp">
#include <type_traits>
#include <cstddef>
Line 44 ⟶ 45:
return rank_v<unqualified_t<T>>;
}
</syntaxhighlight>
</source>
Given the code above the rank of a type T can be calculated at compile time by
:<sourcesyntaxhighlight lang="cpp">rank<T>::value</sourcesyntaxhighlight>
or the shorter form
 
:<sourcesyntaxhighlight lang="cpp">rank_v<T></sourcesyntaxhighlight>
 
Calculating the rank of an expression can be done using
:<sourcesyntaxhighlight lang="cpp">rankof(expr)</sourcesyntaxhighlight>
 
==See also==
Line 62 ⟶ 63:
*[[Rank (J programming language)]], a concept of the same name in the [[J (programming language)|J programming language]]
 
== References ==
<references />{{DEFAULTSORT:Rank (Computer Programming)}}
[[Category:Arrays]]
[[Category:Programming language topics]]