<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Rank_%28computer_programming%29</id>
	<title>Rank (computer programming) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Rank_%28computer_programming%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Rank_(computer_programming)&amp;action=history"/>
	<updated>2026-06-24T12:34:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Rank_(computer_programming)&amp;diff=231612&amp;oldid=prev</id>
		<title>imported&gt;A.Deira.born: added references section</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Rank_(computer_programming)&amp;diff=231612&amp;oldid=prev"/>
		<updated>2025-02-05T10:36:31Z</updated>

		<summary type="html">&lt;p&gt;added references section&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{More citation needed|date=February 2025}}&lt;br /&gt;
&lt;br /&gt;
In [[computer programming]], &amp;#039;&amp;#039;&amp;#039;rank&amp;#039;&amp;#039;&amp;#039; with no further specifications is usually a synonym for (or refers to) &amp;quot;number of dimensions&amp;quot;;&amp;lt;ref&amp;gt;{{Cite web |title=Vocabulary_with_defintions |url=https://files.schudio.com/federation-of-boldmere-schools/files/documents/Vocabulary_with_defintions.docx}}&amp;lt;/ref&amp;gt; thus, a two-dimensional array has rank &amp;#039;&amp;#039;two&amp;#039;&amp;#039;, a three-dimensional array has rank &amp;#039;&amp;#039;three&amp;#039;&amp;#039; and so on.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In the case of [[APL programming language|APL]] the notion applies to every operand; and [[Binary function|dyad]]s (&amp;quot;binary functions&amp;quot;) have a &amp;#039;&amp;#039;left rank&amp;#039;&amp;#039; and a &amp;#039;&amp;#039;right rank&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The box below instead shows how &amp;#039;&amp;#039;rank of a type&amp;#039;&amp;#039; and &amp;#039;&amp;#039;rank of an array expression&amp;#039;&amp;#039; could be defined (in a semi-formal style) for C++ and illustrates a simple way to calculate them at compile time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;type_traits&amp;gt;&lt;br /&gt;
#include &amp;lt;cstddef&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/* Rank of a type&lt;br /&gt;
 * -------------&lt;br /&gt;
 *&lt;br /&gt;
 * Let the rank of a type T be the number of its dimensions if&lt;br /&gt;
 * it is an array; zero otherwise (which is the usual convention)&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;typename T&amp;gt; struct rank&lt;br /&gt;
{&lt;br /&gt;
    static const std::size_t value = 0;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
template&amp;lt;typename T, std::size_t N&amp;gt;&lt;br /&gt;
struct rank&amp;lt;T[N]&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    static const std::size_t value = 1 + rank&amp;lt;T&amp;gt;::value;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;typename T&amp;gt;&lt;br /&gt;
constexpr auto rank_v = rank&amp;lt;T&amp;gt;::value;&lt;br /&gt;
&lt;br /&gt;
/* Rank of an expression&lt;br /&gt;
 *&lt;br /&gt;
 * Let the rank of an expression be the rank of its type&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;typename T&amp;gt;&lt;br /&gt;
using unqualified_t = std::remove_cv_t&amp;lt;std::remove_reference_t&amp;lt;T&amp;gt;&amp;gt;; &lt;br /&gt;
&lt;br /&gt;
template &amp;lt;typename T&amp;gt;&lt;br /&gt;
auto rankof(T&amp;amp;&amp;amp; expr)&lt;br /&gt;
{&lt;br /&gt;
    return rank_v&amp;lt;unqualified_t&amp;lt;T&amp;gt;&amp;gt;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Given the code above the rank of a type T can be calculated at compile time by&lt;br /&gt;
 &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;rank&amp;lt;T&amp;gt;::value&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or the shorter form&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;rank_v&amp;lt;T&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calculating the rank of an expression can be done using&lt;br /&gt;
 &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;rankof(expr)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Rank (linear algebra)]], for a definition of &amp;#039;&amp;#039;rank&amp;#039;&amp;#039; as applied to [[matrix (mathematics)|matrices]]&lt;br /&gt;
*[[Rank (J programming language)]], a concept of the same name in the [[J (programming language)|J programming language]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;{{DEFAULTSORT:Rank (Computer Programming)}}&lt;br /&gt;
[[Category:Arrays]]&lt;br /&gt;
[[Category:Programming language topics]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Compu-lang-stub}}&lt;/div&gt;</summary>
		<author><name>imported&gt;A.Deira.born</name></author>
	</entry>
</feed>