NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Functions
12-numcxx-sharedptr.cxx File Reference
+ Include dependency graph for 12-numcxx-sharedptr.cxx:

Go to the source code of this file.

Functions

void initialize (numcxx::DArray1 &X)
 
double sum_elements (numcxx::DArray1 &X)
 
int main ()
 

Function Documentation

void initialize ( numcxx::DArray1 X)
Examples:
12-numcxx-sharedptr.cxx.

Definition at line 13 of file 12-numcxx-sharedptr.cxx.

14 {
15  const int n=X.size();
16  for (int i=0;i<n;i++) X(i)= 1.0/(double)(1+n-i);
17 }
size_t size() const
Obtain size of array.
Definition: tarray.hxx:58

+ Here is the call graph for this function:

double sum_elements ( numcxx::DArray1 X)
Examples:
12-numcxx-sharedptr.cxx.

Definition at line 20 of file 12-numcxx-sharedptr.cxx.

21 {
22  double sum=0;
23  for (int i=0;i<X.size();i++)sum+=X(i);
24  return sum;
25 }
size_t size() const
Obtain size of array.
Definition: tarray.hxx:58
A::value_type sum(const A &a)
Sum of array or expression.
Definition: util.ixx:81

+ Here is the call graph for this function:

int main ( void  )
Examples:
12-numcxx-sharedptr.cxx.

Definition at line 27 of file 12-numcxx-sharedptr.cxx.

28 {
29  const int n=1.0e7;
30  // call constructor and wrap pointer into smart pointer
32  initialize(*pX); // dereference pointer to obtain reference
33  double s=sum_elements(*pX); // dereference pointer to obtain reference
34  printf("sum=%e\n",s);
35  // smartpointer calls destructor if reference count
36  // reaches zero
37 }
void initialize(numcxx::DArray1 &X)
static std::shared_ptr< TArray1< T > > create(index n1)
Construct smart pointer empty 1D Array.
Definition: tarray1.hxx:81
double sum_elements(numcxx::DArray1 &X)

+ Here is the call graph for this function: