STATICALLY TYPED MATRIX IN C++ LANGUAGE

  • Predrag Rakić Fakultet tehničkih nauka Novi Sad
  • Lazar Stričević Fakultet tehničkih nauka Novi Sad
  • Zorica Suvajdžin Rakić Fakultet tehničkih nauka Novi Sad
Keywords: matrix type, static typing, C , template meta-programming

Abstract

Matrices in contemporary C++ libraries are implemented as if element type and number of dimensions are the only relevant characteristics, included in statically typed part of matrix type. Size of each dimension is treated as variable property and determined dynamically, at runtime. Implemented like this, matrix is typed partially statically and partially dynamically. Types like this are legal in C++ language and generally accepted in C++ community. However, we perceive this hybrid implementation as inconsistent with the spirit of the language. Consequence of this inconsistency is more or less noticeable discrepancy in the matrix operation’s interface and semantic. Matrix implementation in which element type, number of dimensions and size of each dimension are all treated equally as elements of matrix static type is presented in this paper. Proposed implementation is demonstrated in the proof-of-concept C++ template library called Typed Matrix Library (TML). Representing matrices this way enables compile-time correctness verification in matrix operations, incurring no run-time overhead. Our implementation interface is similar to generally accepted, hybrid implementation, requiring no additional information (that programmer is not already aware of) and thus no extra developer effort.
Published
2019-01-15
Section
Articles