Rank (computer Programming) Article Index for
Rank
 

Information About

Rank (computer Programming)




Strictly, no formal definition can be provided which applies to every Programming 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 of APL the notion applies to every operand; and Dyads ("binary functions") have a ''left rank'' and a ''right rank''.

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

// 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 struct rank
{ static const std::size_t value = 0; };

template
struct rank{Link without Title} >
{ static const std::size_t value = 1 + rank::value; };

// Rank of an expression
//
// Let the rank of an expression be the rank of its type
//
template
char(&rankof(t(&) {Link without Title} )) {Link without Title} ;


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

:rank::value

and the rank of an array-expression ''expr'' by

:sizeof(rankof(expr))


SEE ALSO



>