BigUglySpider / EmuLibs

Selection of libraries designed to be used with Emu projects. This was originally a Math library only, but has since been changed to hold all Emu libraries to enable consistency in changes to dependencies (such as EmuCore modifications).
https://biguglyspider.github.io/math
0 stars 0 forks source link

Add STL iterators to Vector (and maybe Matrix) #38

Closed BigUglySpider closed 2 years ago

BigUglySpider commented 2 years ago

EmuMath::Vector

As Vector is effectively a wrapped std::array (although this is not an EmuMath guarantee), it seems reasonable to allow the STL container interface to be used with it. This is especially the case for the few functions which break usual Emu library naming conventions to mimic STL functions (such as at instead of At).

Under current implementations, this will be extremely trivial for value-containing Vector types. Reference-containing Vector types will need some additional work.

EmuMath::Matrix

Matrices already provide a flattened index method of access, which provides column-major access regardless of a Matrix's actual major-storage order.

An STL iterator implementation will likely be in contiguous order to support a method of contiguous flattened access, and provide a similar interface to the Vector implementation.

As of this issue's post, it is uncertain whether an iterator implementation will be provided for Matrix.


Proposal for EmuMath::Vector::iterator (and variants)

As std::array storage is not guaranteed by Vector, it would be preferable to implement a custom iterator for all kinds of Vector, instead of conditionally choosing between std::array::iterator (and variants) or a custom iterator.

Implementation

BigUglySpider commented 2 years ago

Addressed as of commit d4b90245fe84297b57fa18a8bec1e66a5f4be595 (for EmuMath::Vector).

Matrix implementation is still undecided, but no decision is being made for now. It will likely be decided after mutation (and related operations) is complete.

Closing this issue as a result; if Matrix STL iterator support is considered desirable, another issue should be made.

BigUglySpider commented 2 years ago

STL Iterators have been added to Matrix as of commit 0c0800af7fcc2b8a84db0de42a75233bdb05a76d, pull request #46.