Classes var_lens_less_final and con_lens_less_final differ substiantially from the other lenses presented here. In particular, they cannot be lensed by other lenses; thus the "final" in the name. These two lenses amount to housing for a subscript to a matrix, and they come close to being the multidimensional equivalent of the Standard Library's std::vector::iterator and std::vector::const_iterator.
In line with X_lens_less_dimen, the subscript stored inside the lens is called a marker.
As an example, with a matrix whose form is ( 1 =< 3, 2 =< 6, 5 =< 8 ), an X_lens_less_final constructor would need a parameter similar to this:
vec_si const w {2, 4, 7};where the number of components is equal to the dimensionality of the matrix being lensed. In contrast with X_lens_less_dimen, there is no use for a null_int. This vec_si parameter becomes the current marker, and the corresponding component will be the only component visible until the marker is changed.
There are eight functions to manage markers:
vec_si const & marker_get () const; sign_int marker_get (sign_int const pos) const; sign_int marker_bot (sign_int const pos) const; sign_int marker_top (sign_int const pos) const; void marker_set (vec_si const & v); void marker_set (sign_int const pos, sign_int const val); void marker_add (sign_int const pos, sign_int const val); void marker_sub (sign_int const pos, sign_int const val);Available for all X_lens_less_final:
Because only one component is visible at any time, the functions to access it differ somewhat from those for the other lenses:
compo get () const; // var_ and con_ compo const & con_ref () const; // var_ and con_ compo & var_ref () const; // var_ only void set (compo const c) const; // var_ onlyAs with X_lens_less_dimen, no alarm is given if the programmer sets the marker to a value out of range — this is analogous to when the programmer sets a Standard Library iterator to a value that does not reference a component. The bool function can_deref is available, and it returns true when the marker is within range; false when is out of range. Setting a marker out of range does not cause malfunction as long as it is not deferenced; subsequently setting the marker to a value within range will allow it to be deferenced without trouble.
#include "SOME_DIRECTORY/mat_gen_dim.h" using namespace mat_gen_dim; int main () { form const frm_a {blt{1,3},blt{2,6},blt{5,8}}; cout << "\nfrm_a: " << frm_a; var_matrix<double> mat_a {sub_matrix_linear (frm_a, 0.0)}; cout << "\nmat_a before: " << mat_a; vec_si const w {2, 4, 7}; var_lens_less_final<double> ald_b {mat_a, w}; cout << "\nald_b with marker at (2, 4, 7): " << ald_b.get(); ald_b.marker_set (0, 1); ald_b.marker_set (2, 6); cout << "\nald_b with marker at (1, 4, 6): " << ald_b.get(); ald_b.marker_set (vec_si {2,3,5}); ald_b.set (382.0); cout << "\nmat_a after: " << mat_a; return 0; }yields this output:
frm_a: ( 1 =< 3, 2 =< 6, 5 =< 8 ) mat_a before: ( 1 2 5 ) = 0.125 ( 1 2 6 ) = 0.126 ( 1 2 7 ) = 0.127 ( 1 3 5 ) = 0.135 ( 1 3 6 ) = 0.136 ( 1 3 7 ) = 0.137 ( 1 4 5 ) = 0.145 ( 1 4 6 ) = 0.146 ( 1 4 7 ) = 0.147 ( 1 5 5 ) = 0.155 ( 1 5 6 ) = 0.156 ( 1 5 7 ) = 0.157 ( 2 2 5 ) = 0.225 ( 2 2 6 ) = 0.226 ( 2 2 7 ) = 0.227 ( 2 3 5 ) = 0.235 ( 2 3 6 ) = 0.236 ( 2 3 7 ) = 0.237 ( 2 4 5 ) = 0.245 ( 2 4 6 ) = 0.246 ( 2 4 7 ) = 0.247 ( 2 5 5 ) = 0.255 ( 2 5 6 ) = 0.256 ( 2 5 7 ) = 0.257 ald_b with marker at (2, 4, 7): 0.247 ald_b with marker at (1, 4, 6): 0.146 mat_a after: ( 1 2 5 ) = 0.125 ( 1 2 6 ) = 0.126 ( 1 2 7 ) = 0.127 ( 1 3 5 ) = 0.135 ( 1 3 6 ) = 0.136 ( 1 3 7 ) = 0.137 ( 1 4 5 ) = 0.145 ( 1 4 6 ) = 0.146 ( 1 4 7 ) = 0.147 ( 1 5 5 ) = 0.155 ( 1 5 6 ) = 0.156 ( 1 5 7 ) = 0.157 ( 2 2 5 ) = 0.225 ( 2 2 6 ) = 0.226 ( 2 2 7 ) = 0.227 ( 2 3 5 ) = 382 ( 2 3 6 ) = 0.236 ( 2 3 7 ) = 0.237 ( 2 4 5 ) = 0.245 ( 2 4 6 ) = 0.246 ( 2 4 7 ) = 0.247 ( 2 5 5 ) = 0.255 ( 2 5 6 ) = 0.256 ( 2 5 7 ) = 0.257