section 7B1
alone_X

home

Here are three functions that apply the same operation to all components of a matrix:

• alone_non_var modifies the components of a matrix and returns nothing:
```template <
typename oper,
typename compo_a,
typename alloc_a = std::allocator <compo_a> >
void alone_non_var (
var_matrix_base<compo_a,alloc_a> const & mat_a
);
```
• alone_ret_var modifies the components of a matrix and returns that modified version:
```template <
typename oper,
typename compo_a,
typename alloc_a = std::allocator <compo_a>
> var_matrix <compo_a,alloc_a> alone_ret_var (
var_matrix_base<compo_a,alloc_a> const & mat_a
);
```
• alone_ret_con modifies the components of a copy of a matrix, and returns the copy:
```template <
typename oper,
typename compo_a,
typename compo_z = compo_a,
typename alloc_a = std::allocator <compo_a>,
typename alloc_z = std::allocator <compo_z>
> var_matrix<compo_z,alloc_z> alone_ret_con (
sub_matrix_base<compo_a,alloc_a> const & mat_a
);
```

As an example, this program:

```#include "SOME_DIRECTORY/mat_gen_dim.h"
using namespace mat_gen_dim;

form const frm {blt{1,3},blt{2,6},blt{5,7}};

int main () {
std::cout.setf (std::ios::fixed, std::ios::floatfield);
std::cout.precision (3);

{
struct neg_non_var {
void operator() (double & a) { a = -a; }
};

cout << "\n\n -- negate a matrix, return nothing ";
var_matrix<double> mat_a1 {sub_matrix_linear (frm, 1.0)};
cout << "\n mat_a1 before: " << mat_a1;

alone_non_var <neg_non_var,double> (mat_a1);

cout << "\n mat_a1 after: " << mat_a1;
} {
struct neg_ret_var {
double operator() (double & a) { return a = -a; }
};

cout << "\n\n -- negate a matrix, and return a copy of it ";
var_matrix<double> mat_a2 {sub_matrix_linear (frm, 1.0)};
cout << "\n mat_a2 before: " << mat_a2;

con_matrix<double> mat_z2 {
alone_ret_var <neg_ret_var,double> (mat_a2)
};

cout << "\n mat_a2 after: " << mat_a2;
cout << "\n mat_z2 == what is returned: " << mat_z2;
} {
struct neg_ret_con {
double operator() (double const a) { return -a; }
};

cout << "\n\n -- negate a copy of a matrix, and return that copy ";
con_matrix<double> mat_a3 {sub_matrix_linear (frm, 1.0)};
cout << "\n mat_a3 before: " << mat_a3;

con_matrix<double> mat_z3 {
alone_ret_con <neg_ret_con,double> (mat_a3)
};

cout << "\n mat_a3 after: " << mat_a3;
cout << "\n mat_z3 == what is returned: " << mat_z3;
}
return 0;
}
```
yields this output:
``` -- negate a matrix, return nothing
mat_a1 before:
( 1 2 5 ) = 1.125    ( 1 2 6 ) = 1.126    ( 1 3 5 ) = 1.135    ( 1 3 6 ) = 1.136
( 1 4 5 ) = 1.145    ( 1 4 6 ) = 1.146    ( 1 5 5 ) = 1.155    ( 1 5 6 ) = 1.156
( 2 2 5 ) = 1.225    ( 2 2 6 ) = 1.226    ( 2 3 5 ) = 1.235    ( 2 3 6 ) = 1.236
( 2 4 5 ) = 1.245    ( 2 4 6 ) = 1.246    ( 2 5 5 ) = 1.255    ( 2 5 6 ) = 1.256
mat_a1 after:
( 1 2 5 ) = -1.125    ( 1 2 6 ) = -1.126    ( 1 3 5 ) = -1.135    ( 1 3 6 ) = -1.136
( 1 4 5 ) = -1.145    ( 1 4 6 ) = -1.146    ( 1 5 5 ) = -1.155    ( 1 5 6 ) = -1.156
( 2 2 5 ) = -1.225    ( 2 2 6 ) = -1.226    ( 2 3 5 ) = -1.235    ( 2 3 6 ) = -1.236
( 2 4 5 ) = -1.245    ( 2 4 6 ) = -1.246    ( 2 5 5 ) = -1.255    ( 2 5 6 ) = -1.256

-- negate a matrix, and return a copy of it
mat_a2 before:
( 1 2 5 ) = 1.125    ( 1 2 6 ) = 1.126    ( 1 3 5 ) = 1.135    ( 1 3 6 ) = 1.136
( 1 4 5 ) = 1.145    ( 1 4 6 ) = 1.146    ( 1 5 5 ) = 1.155    ( 1 5 6 ) = 1.156
( 2 2 5 ) = 1.225    ( 2 2 6 ) = 1.226    ( 2 3 5 ) = 1.235    ( 2 3 6 ) = 1.236
( 2 4 5 ) = 1.245    ( 2 4 6 ) = 1.246    ( 2 5 5 ) = 1.255    ( 2 5 6 ) = 1.256
mat_a2 after:
( 1 2 5 ) = -1.125    ( 1 2 6 ) = -1.126    ( 1 3 5 ) = -1.135    ( 1 3 6 ) = -1.136
( 1 4 5 ) = -1.145    ( 1 4 6 ) = -1.146    ( 1 5 5 ) = -1.155    ( 1 5 6 ) = -1.156
( 2 2 5 ) = -1.225    ( 2 2 6 ) = -1.226    ( 2 3 5 ) = -1.235    ( 2 3 6 ) = -1.236
( 2 4 5 ) = -1.245    ( 2 4 6 ) = -1.246    ( 2 5 5 ) = -1.255    ( 2 5 6 ) = -1.256
mat_z2 == what is returned:
( 1 2 5 ) = -1.125    ( 1 2 6 ) = -1.126    ( 1 3 5 ) = -1.135    ( 1 3 6 ) = -1.136
( 1 4 5 ) = -1.145    ( 1 4 6 ) = -1.146    ( 1 5 5 ) = -1.155    ( 1 5 6 ) = -1.156
( 2 2 5 ) = -1.225    ( 2 2 6 ) = -1.226    ( 2 3 5 ) = -1.235    ( 2 3 6 ) = -1.236
( 2 4 5 ) = -1.245    ( 2 4 6 ) = -1.246    ( 2 5 5 ) = -1.255    ( 2 5 6 ) = -1.256

-- negate a copy of a matrix, and return that copy
mat_a3 before:
( 1 2 5 ) = 1.125    ( 1 2 6 ) = 1.126    ( 1 3 5 ) = 1.135    ( 1 3 6 ) = 1.136
( 1 4 5 ) = 1.145    ( 1 4 6 ) = 1.146    ( 1 5 5 ) = 1.155    ( 1 5 6 ) = 1.156
( 2 2 5 ) = 1.225    ( 2 2 6 ) = 1.226    ( 2 3 5 ) = 1.235    ( 2 3 6 ) = 1.236
( 2 4 5 ) = 1.245    ( 2 4 6 ) = 1.246    ( 2 5 5 ) = 1.255    ( 2 5 6 ) = 1.256
mat_a3 after:
( 1 2 5 ) = 1.125    ( 1 2 6 ) = 1.126    ( 1 3 5 ) = 1.135    ( 1 3 6 ) = 1.136
( 1 4 5 ) = 1.145    ( 1 4 6 ) = 1.146    ( 1 5 5 ) = 1.155    ( 1 5 6 ) = 1.156
( 2 2 5 ) = 1.225    ( 2 2 6 ) = 1.226    ( 2 3 5 ) = 1.235    ( 2 3 6 ) = 1.236
( 2 4 5 ) = 1.245    ( 2 4 6 ) = 1.246    ( 2 5 5 ) = 1.255    ( 2 5 6 ) = 1.256
mat_z3 == what is returned:
( 1 2 5 ) = -1.125    ( 1 2 6 ) = -1.126    ( 1 3 5 ) = -1.135    ( 1 3 6 ) = -1.136
( 1 4 5 ) = -1.145    ( 1 4 6 ) = -1.146    ( 1 5 5 ) = -1.155    ( 1 5 6 ) = -1.156
( 2 2 5 ) = -1.225    ( 2 2 6 ) = -1.226    ( 2 3 5 ) = -1.235    ( 2 3 6 ) = -1.236
( 2 4 5 ) = -1.245    ( 2 4 6 ) = -1.246    ( 2 5 5 ) = -1.255    ( 2 5 6 ) = -1.256
```