1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

///
/// In the `main` function we again start with a typedef for a `GeMatrix` with
/// elements of type `double` that are stored column-wise in memory.  Also,
/// we define a suitable range operator.
///
int
main()
{
    typedef FullStorage<double, ColMajor>  FS;
    typedef GeMatrix<FS>                   GeMatrix;
    const Underscore<GeMatrix::IndexType>  _;

///
/// Then we setup some matrix.
///
    GeMatrix  A(3,4);
    A = 1,  2,  3,  4,
        5,  6,  7,  8,
        9101112;

    cout << "A = " << A << endl;

///
/// Matrix `B` is of type `const GeMatrix::View`.  So in particular this matrix
/// is in const context.
///
    const auto B = A(_(1,3),_);

///
/// Matrix `C` is of type `GeMatrix::ConstView` but it is *not* in const
/// context.
///
    auto C = B(_(1,3),_);

///
/// Matrix `D` would be of type `GeMatrix::View` and would reference a part
/// of a matrix of type `GeMatrix::ConstView`.  This would violate *const
/// correctness*.
    auto D = C(_(1,3),_);

    D(1,1) = 666;
    cout << "D = " << D << endl;
}