The template-class gsl::vector_view is one of two descendants of gsl::v_iface.
The other is gsl::vector.
gsl::vector_view exists to provide constructors for gsl::v_iface.
- gsl::vector_view provides no interface other than construction.
- gsl::v_iface provides almost all of the interfaces that GSL's native vector provides.
- An instance constructed via one of the template-specializations of gsl::vector_view does not own memory allocated for elements in a vector.
- Internally, the return-value of
gsl_vector_view_array()
is stored on the stack in the instance of gsl::vector_view.
- The instance of
gsl_vector_view
returned by gsl_vector_view_array()
consumes about 40 bytes on a 64-bit machine.
- There is on the stack no pointer to the virtual-function table.
- There is no virtual destructor in the inheritance-chain.
Example
The template-parameters to gsl::vector_view often need not be specified because they are deduced by the compiler.
Here is an example-program:
using std::cout;
using std::endl;
int main() {
complex<float> const a1[]= {{1.0f, -1.0f}, {0.5f, 0.6f}};
vector_view v1= a1;
cout << "\n"
<< "Instance of gsl_vector_view consumes 40 bytes on 64-bit hardware.\n"
<< "sizeof(v1)=" << sizeof(v1) << " v1=" << v1 << "\n"
<<
"v1.get(1)=" << v1.
get(1) << endl;
float a4[]= {1, 2, 3, 4, 5, 6};
vector_view v4(a4, 4);
cout << "\n"
<< "sizeof(v4)=" << sizeof(v4) << " v4=" << v4 << "\n"
<< "v4.subvector(2, 1, 2)=" << v4.subvector(2, 1, 2) << endl;
short a5[]= {1, 2, 3, 4, 5, 6};
vector_view v5(a5, 3, 2);
cout << "\n"
<< "sizeof(v5)=" << sizeof(v5) << " v5=" << v5 << "\n"
<< "v5.max_index()=" << v5.max_index() << endl;
}
And here is its output:
Instance of gsl_vector_view consumes 40 bytes on 64-bit hardware.
sizeof(v1)=40 v1=[(1,-1),(0.5,0.6)]
v1.get(1)=(0.5,0.6)
sizeof(v4)=40 v4=[1,2,3,4]
v4.subvector(2, 1, 2)=[2,4]
sizeof(v5)=40 v5=[1,3,5]
v5.max_index()=2