// -*- coding: utf-8 -*- // Time-stamp: // Class for arrays of floats // - Copy constructor and copy assignment and destructor // - Move semantics with move constructor and move assignment // - initializer_list constructor #ifndef ARRAY_H #define ARRAY_H #include class Array { public: // Constructors // Default constructor: no allocation Array(); // Constructor from a size // Allocate the array but no initialization Array(int n); // Copy constructor Array(const Array& a); // Move constructor Array(Array&& a); // Initializer list constructor Array(std::initializer_list list); // Copy assignment operator Array& operator=(const Array& a); // Move assignment operator Array& operator=(Array&& a); // Access operators // Access operator to non constant objets double& operator[](int i); // Access operator to constant objets const double& operator[](int i) const; // Destructor ~Array(); // Size int size() const { return length; } private: // Allocate dymanic array // + length must be valid void alloc(); // Free dynamic array void free(); // Copy values from t into the dynamic array // + length must be valid // + p must valid: dynamic array already allocated void copy(double* t); int length; // Size of the dynamic array double *p; // Address of the dynamic array or nullptr if none }; #endif