gslcpp
Modern-C++ Wrapper for GSL
Public Types | Public Member Functions | List of all members
gsl::vector_view< T, S > Struct Template Reference

Constructor-type for vector-by-reference whose storage is not owned by instance of view. More...

#include <vector-view.hpp>

Inheritance diagram for gsl::vector_view< T, S >:
[legend]
Collaboration diagram for gsl::vector_view< T, S >:
[legend]

Public Types

using P = v_iface< T, S, v_view >
 Type of ancestor.
 
- Public Types inherited from gsl::v_iface< T, 0, v_view >
enum  
 
using E = T
 Element-type needed by gsl::v_iterator<v_iface>.
 
using iterator = v_iterator< v_iface >
 Type of iterator that points to mutable element.
 
using const_iterator = v_iterator< v_iface const >
 Type of iterator that points to immutable element.
 

Public Member Functions

 vector_view (T *b, size_t n, size_t s=1)
 Initialize view of standard (decayed) C-array. More...
 
 vector_view (T(&b)[S])
 Initialize view of non-decayed C-array. More...
 
- Public Member Functions inherited from gsl::v_iface< T, 0, v_view >
iterator begin ()
 Iterator that points to first element. More...
 
const_iterator begin () const
 Iterator that points to first element. More...
 
iterator end ()
 Iterator that points to element just past last element. More...
 
const_iterator end () const
 Iterator that points to element just past last element. More...
 
size_t size () const
 Size of vector. More...
 
T * data ()
 Pointer to first element in vector. More...
 
const T * data () const
 Pointer to first element in immutable vector. More...
 
get (size_t i) const
 Read element with bounds-checking. More...
 
void set (size_t i, T const &x)
 Write element with bounds-checking. More...
 
const T & operator[] (size_t i) const
 Read element without bounds-checking. More...
 
T & operator[] (size_t i)
 Write element without bounds-checking. More...
 
T * ptr (size_t i)
 Retrieve pointer to ith element with bounds-checking. More...
 
const T * ptr (size_t i) const
 Retrieve pointer to ith element with bounds-checking. More...
 
void set_all (T const &x)
 Set every element. More...
 
void set_zero ()
 Set every element to zero.
 
int set_basis (size_t i)
 Set element at offset i to unity and every other element to zero. More...
 
int fwrite (FILE *f) const
 Write non-portable binary-image of vector to file. More...
 
int fread (FILE *f)
 Read non-portable binary-image of vector from file. More...
 
int fprintf (FILE *flp, char const *fmt) const
 Write ASCII-formatted representation of vector to file. More...
 
int fscanf (FILE *f)
 Read ASCII-formatted representation of vector from file. More...
 
v_iface< element_t< T >, N, v_viewreal ()
 View of real-part of complex vector. More...
 
v_iface< element_t< T > const, N, v_viewreal () const
 View of real-part of complex vector. More...
 
v_iface< element_t< T >, N, v_viewimag ()
 View of imaginary-part of complex vector. More...
 
v_iface< element_t< T > const, N, v_viewimag () const
 View of imaginary-part of complex vector. More...
 
v_iface< T, N, v_viewsubvector (size_t n, size_t i=0, size_t s=1)
 View of subvector of vector. More...
 
v_iface< T const, N, v_viewsubvector (size_t n, size_t i=0, size_t s=1) const
 View of subvector of vector. More...
 
v_iface< T, N, v_viewview ()
 View of vector. More...
 
v_iface< T const, N, v_viewview () const
 View of vector. More...
 
int swap_elements (size_t i, size_t j)
 Swap elements within this vector. More...
 
int reverse ()
 Reverse order of elements. More...
 
int add (v_iface< T, ON, OV > const &b)
 Add contents of b into this vector in place. More...
 
int sub (v_iface< T, ON, OV > const &b)
 Subtract contents of b from this vector in place. More...
 
int mul (v_iface< T, ON, OV > const &b)
 Multiply contents of b into this vector in place. More...
 
int div (v_iface< T, ON, OV > const &b)
 Divide contents of b into this vector in place. More...
 
v_ifaceoperator+= (v_iface< T, ON, OV > const &b)
 Add contents of b into this vector in place. More...
 
v_ifaceoperator+= (T const &x)
 Add constant into each element of this vector in place. More...
 
v_ifaceoperator-= (v_iface< T, ON, OV > const &b)
 Subtract contents of b from this vector in place. More...
 
v_ifaceoperator*= (v_iface< T, ON, OV > const &b)
 Multiply contents of b into this vector in place. More...
 
v_ifaceoperator*= (T const &x)
 Multiply scalar into this vector in place. More...
 
v_ifaceoperator/= (v_iface< T, ON, OV > const &b)
 Divide contents of b into this vector in place. More...
 
v_ifaceoperator= (v_iface< T, ON, OV > const &b)
 Copy contents of b into this vector. More...
 
v_ifaceoperator= (v_iface const &b)
 Copy contents of b into this vector. More...
 
 v_iface (v_iface &&)=default
 Enable move-constructor in gsl::v_stor to work.
 
int scale (T const &x)
 Multiply scalar into this vector in place. More...
 
int add_constant (T const &x)
 Add constant into each element of this vector in place. More...
 
sum () const
 Sum of elements. More...
 
max () const
 Greatest value of any element. More...
 
min () const
 Least value of any element. More...
 
void minmax (T &min, T &max) const
 Greatest value and least value of any element. More...
 
size_t max_index () const
 Offset of greatest value. More...
 
size_t min_index () const
 Offset of least value. More...
 
void minmax_index (size_t &imin, size_t &imax) const
 Offset of least value and offset of greatest value. More...
 
bool isnull () const
 True only if every element have zero value. More...
 
bool ispos () const
 True only if every element be positive. More...
 
bool isneg () const
 True only if every element be negative. More...
 
bool isnonneg () const
 True only if every element be non-negative. More...
 
- Public Member Functions inherited from gsl::v_view< T, N >
auto * v ()
 Reference to GSL's interface to vector. More...
 
const auto * v () const
 Reference to GSL's interface to vector. More...
 
 v_view (w_vector_view< T > const &v)
 Constructor called by TBS. More...
 
auto & cview () const
 GSL's native, C-language interface to vector-view. More...
 

Detailed Description

template<typename T, size_t S = 0>
struct gsl::vector_view< T, S >

Constructor-type for vector-by-reference whose storage is not owned by instance of view.

Despite its name, vector_view allows both viewing and modifying data that it refers to. These data are presented as if they were in a virtual vector represented by the intance.

vector_view has its interface to storage given by gsl::v_view, and most of the ordinary vector-interface is given by gsl::v_iface.

vector_view inherits these and provides template-constructors for an instance of type gsl::v_iface<T, S, v_view>.

Template-value-parameter S indicates the number of elements in the vector at compile-time. If S be zero, then the number of elements in the vector is determined at run-time.

When using vector_view, one typically does not need to specify template-parameters:

int main() {
double g[]= {1, 2, 3, 4, 5, 6};
// Deduce vector_view<double, 6> with stride=1:
// Deduce vector_view<double, 0> with three elements and stride=2:
gsl::vector_view v2(g, 3, 2);
v2[1]= 10; // Now g[2] is no longer 3 but 10.
// Deduce vector_view<double const, 0> with three elements and stride=2:
double const *h= g;
gsl::vector_view v3(h, 3, 2); // Only fetching allowed, not setting.
return 0;
}
Template Parameters
TType of each element in vector.
SCompile-time number of elements (0 for number set at run-time).

Definition at line 64 of file vector-view.hpp.

Constructor & Destructor Documentation

◆ vector_view() [1/2]

template<typename T , size_t S = 0>
gsl::vector_view< T, S >::vector_view ( T *  b,
size_t  n,
size_t  s = 1 
)
inline

Initialize view of standard (decayed) C-array.

Arguments are ordered differently from those given to gsl_vector_viewiew_array_with_stride(). Putting stride at end allows it to have default value of 1.

Parameters
bPointer to first element of array and of view.
nNumber of elements in view.
sStride of elements relative to array.

Definition at line 77 of file vector-view.hpp.

77 : P(w_vector_view_array(b, s, n)) {}

◆ vector_view() [2/2]

template<typename T , size_t S = 0>
gsl::vector_view< T, S >::vector_view ( T(&)  b[S])
inline

Initialize view of non-decayed C-array.

Parameters
bReference to non-decayed C-array.

Definition at line 81 of file vector-view.hpp.

81 : P(w_vector_view_array(b, 1, S)) {}

The documentation for this struct was generated from the following file:
vector-view.hpp
Definition for gsl::vector_view.
gsl::w_vector_view_array
auto w_vector_view_array(double *b, size_t s, size_t n)
Initialize view of C-style array as vector.
Definition: vector-view-array.hpp:17
gsl::vector_view
Constructor-type for vector-by-reference whose storage is not owned by instance of view.
Definition: vector-view.hpp:64
gsl::vector_view::P
v_iface< T, S, v_view > P
Type of ancestor.
Definition: vector-view.hpp:65