Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Rank (computer programming)

From Wikipedia, the free encyclopedia
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Rank" computer programming – news ·newspapers ·books ·scholar ·JSTOR
(February 2025) (Learn how and when to remove this message)

Incomputer programming,rank with no further specifications is usually a synonym for (or refers to) "number of dimensions";[1] thus, a two-dimensional array has ranktwo, a three-dimensional array has rankthree and so on.Strictly, no formal definition can be provided which applies to everyprogramming language, since each of them has its own concepts,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 the case ofAPL the notion applies to every operand; anddyads ("binary functions") have aleft rank and aright rank.

The box below instead shows howrank of a type andrank 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>/* Rank of a type * ------------- * * Let the rank of a type T be the number of its dimensions if * it is an array; zero otherwise (which is the usual convention) */template<typenameT>structrank{staticconststd::size_tvalue=0;};template<typenameT,std::size_tN>structrank<T[N]>{staticconststd::size_tvalue=1+rank<T>::value;};template<typenameT>constexprautorank_v=rank<T>::value;/* Rank of an expression * * Let the rank of an expression be the rank of its type */template<typenameT>usingunqualified_t=std::remove_cv_t<std::remove_reference_t<T>>;template<typenameT>autorankof(T&&expr){returnrank_v<unqualified_t<T>>;}

Given the code above the rank of a type T can be calculated at compile time by

rank<T>::value

or the shorter form

rank_v<T>

Calculating the rank of an expression can be done using

rankof(expr)

See also

[edit]

References

[edit]
  1. ^"Vocabulary_with_defintions".


Stub icon

Thisprogramming-language-related article is astub. You can help Wikipedia byexpanding it.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Rank_(computer_programming)&oldid=1274076977"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp