comparison liboctave/array/Array.h @ 21139:538b57866b90

consistently use "typename" intead of "class" in template declarations * Object.h, QtHandlesUtils.cc, QtHandlesUtils.h, ToolBarButton.cc, ToolBarButton.h, Cell.h, __lin_interpn__.cc, bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, filter.cc, gcd.cc, graphics.cc, help.cc, kron.cc, lookup.cc, ls-mat5.cc, ls-oct-text.h, lu.cc, max.cc, mgorth.cc, oct-map.cc, oct-map.h, oct-stream.cc, oct-stream.h, octave-link.h, pr-output.cc, profiler.h, schur.cc, sparse-xdiv.cc, sparse-xpow.cc, sqrtm.cc, symtab.h, tril.cc, typecast.cc, variables.cc, xdiv.cc, zfstream.h, __init_fltk__.cc, __magick_read__.cc, chol.cc, qr.cc, ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h, ov-base-sparse.cc, ov-base-sparse.h, ov-base.h, ov-classdef.cc, ov-int-traits.h, ov-java.h, ov-usr-fcn.h, ov.cc, ov.h, op-dms-template.cc, oct-parse.in.yy, parse.h, pt-mat.cc, Array-b.cc, Array.cc, Array.h, CDiagMatrix.h, CMatrix.h, CNDArray.h, DiagArray2.cc, DiagArray2.h, MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.cc, MSparse.h, MatrixType.cc, Sparse.cc, Sparse.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, fCDiagMatrix.h, fCMatrix.h, fCNDArray.h, fDiagMatrix.h, fMatrix.h, fNDArray.h, idx-vector.cc, idx-vector.h, intNDArray.cc, intNDArray.h, DET.h, base-aepbal.h, base-lu.cc, base-lu.h, base-qr.cc, base-qr.h, bsxfun-defs.cc, eigs-base.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, oct-convn.cc, oct-fftw.cc, oct-norm.cc, sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc, sparse-base-lu.h, sparse-dmsolve.cc, mx-inlines.cc, action-container.h, base-list.h, lo-traits.h, lo-utils.h, oct-base64.h, oct-binmap.h, oct-cmplx.h, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.h, oct-refcount.h, oct-sort.cc, oct-sort.h: Use "typename" instead of "class" in template declarations.
author John W. Eaton <jwe@octave.org>
date Sun, 24 Jan 2016 13:50:04 -0500
parents 2e5c1f766ac9
children a83e7a384ee0
comparison
equal deleted inserted replaced
21138:e2fca7d79169 21139:538b57866b90
39 #include "oct-sort.h" 39 #include "oct-sort.h"
40 #include "quit.h" 40 #include "quit.h"
41 #include "oct-refcount.h" 41 #include "oct-refcount.h"
42 42
43 //! Handles the reference counting for all the derived classes. 43 //! Handles the reference counting for all the derived classes.
44 template <class T> 44 template <typename T>
45 class 45 class
46 Array 46 Array
47 { 47 {
48 protected: 48 protected:
49 49
60 : data (new T [l]), len (l), count (1) 60 : data (new T [l]), len (l), count (1)
61 { 61 {
62 std::copy (d, d+l, data); 62 std::copy (d, d+l, data);
63 } 63 }
64 64
65 template <class U> 65 template <typename U>
66 ArrayRep (U *d, octave_idx_type l) 66 ArrayRep (U *d, octave_idx_type l)
67 : data (new T [l]), len (l), count (1) 67 : data (new T [l]), len (l), count (1)
68 { 68 {
69 std::copy (d, d+l, data); 69 std::copy (d, d+l, data);
70 } 70 }
198 198
199 //! Reshape constructor. 199 //! Reshape constructor.
200 Array (const Array<T>& a, const dim_vector& dv); 200 Array (const Array<T>& a, const dim_vector& dv);
201 201
202 //! Type conversion case. 202 //! Type conversion case.
203 template <class U> 203 template <typename U>
204 Array (const Array<U>& a) 204 Array (const Array<U>& a)
205 : dimensions (a.dims ()), 205 : dimensions (a.dims ()),
206 rep (new typename Array<T>::ArrayRep (a.data (), a.numel ())), 206 rep (new typename Array<T>::ArrayRep (a.data (), a.numel ())),
207 slice_data (rep->data), slice_len (rep->len) 207 slice_data (rep->data), slice_len (rep->len)
208 { } 208 { }
658 static Array<T> 658 static Array<T>
659 cat (int dim, octave_idx_type n, const Array<T> *array_list); 659 cat (int dim, octave_idx_type n, const Array<T> *array_list);
660 660
661 //! Apply function fcn to each element of the Array<T>. This function 661 //! Apply function fcn to each element of the Array<T>. This function
662 //! is optimised with a manually unrolled loop. 662 //! is optimised with a manually unrolled loop.
663 template <class U, class F> 663 template <typename U, typename F>
664 Array<U> 664 Array<U>
665 map (F fcn) const 665 map (F fcn) const
666 { 666 {
667 octave_idx_type len = numel (); 667 octave_idx_type len = numel ();
668 668
690 return result; 690 return result;
691 } 691 }
692 692
693 //@{ 693 //@{
694 //! Overloads for function references. 694 //! Overloads for function references.
695 template <class U> 695 template <typename U>
696 Array<U> 696 Array<U>
697 map (U (&fcn) (T)) const 697 map (U (&fcn) (T)) const
698 { return map<U, U (&) (T)> (fcn); } 698 { return map<U, U (&) (T)> (fcn); }
699 699
700 template <class U> 700 template <typename U>
701 Array<U> 701 Array<U>
702 map (U (&fcn) (const T&)) const 702 map (U (&fcn) (const T&)) const
703 { return map<U, U (&) (const T&)> (fcn); } 703 { return map<U, U (&) (const T&)> (fcn); }
704 //@} 704 //@}
705 705
706 //! Generic any/all test functionality with arbitrary predicate. 706 //! Generic any/all test functionality with arbitrary predicate.
707 template <class F, bool zero> 707 template <typename F, bool zero>
708 bool test (F fcn) const 708 bool test (F fcn) const
709 { 709 {
710 return any_all_test<F, T, zero> (fcn, data (), numel ()); 710 return any_all_test<F, T, zero> (fcn, data (), numel ());
711 } 711 }
712 712
713 //@{ 713 //@{
714 //! Simpler calls. 714 //! Simpler calls.
715 template <class F> 715 template <typename F>
716 bool test_any (F fcn) const 716 bool test_any (F fcn) const
717 { return test<F, false> (fcn); } 717 { return test<F, false> (fcn); }
718 718
719 template <class F> 719 template <typename F>
720 bool test_all (F fcn) const 720 bool test_all (F fcn) const
721 { return test<F, true> (fcn); } 721 { return test<F, true> (fcn); }
722 //@} 722 //@}
723 723
724 //@{ 724 //@{
734 734
735 bool test_all (bool (&fcn) (const T&)) const 735 bool test_all (bool (&fcn) (const T&)) const
736 { return test<bool (&) (const T&), true> (fcn); } 736 { return test<bool (&) (const T&), true> (fcn); }
737 //@} 737 //@}
738 738
739 template <class U> friend class Array; 739 template <typename U> friend class Array;
740 740
741 //! Returns true if this->dims () == dv, and if so, replaces this->dimensions 741 //! Returns true if this->dims () == dv, and if so, replaces this->dimensions
742 //! by a shallow copy of dv. This is useful for maintaining several arrays with 742 //! by a shallow copy of dv. This is useful for maintaining several arrays with
743 //! supposedly equal dimensions (e.g. structs in the interpreter). 743 //! supposedly equal dimensions (e.g. structs in the interpreter).
744 bool optimize_dimensions (const dim_vector& dv); 744 bool optimize_dimensions (const dim_vector& dv);
762 //! This is a simple wrapper template that will subclass an Array<T> 762 //! This is a simple wrapper template that will subclass an Array<T>
763 //! type or any later type derived from it and override the default 763 //! type or any later type derived from it and override the default
764 //! non-const operator() to not check for the array's uniqueness. It 764 //! non-const operator() to not check for the array's uniqueness. It
765 //! is, however, the user's responsibility to ensure the array is 765 //! is, however, the user's responsibility to ensure the array is
766 //! actually unaliased whenever elements are accessed. 766 //! actually unaliased whenever elements are accessed.
767 template<class ArrayClass> 767 template <typename ArrayClass>
768 class NoAlias : public ArrayClass 768 class NoAlias : public ArrayClass
769 { 769 {
770 typedef typename ArrayClass::element_type T; 770 typedef typename ArrayClass::element_type T;
771 public: 771 public:
772 NoAlias () : ArrayClass () { } 772 NoAlias () : ArrayClass () { }
773 773
774 // FIXME: this would be simpler once C++0x is available 774 // FIXME: this would be simpler once C++0x is available
775 template <class X> 775 template <typename X>
776 explicit NoAlias (X x) : ArrayClass (x) { } 776 explicit NoAlias (X x) : ArrayClass (x) { }
777 777
778 template <class X, class Y> 778 template <typename X, typename Y>
779 explicit NoAlias (X x, Y y) : ArrayClass (x, y) { } 779 explicit NoAlias (X x, Y y) : ArrayClass (x, y) { }
780 780
781 template <class X, class Y, class Z> 781 template <typename X, typename Y, typename Z>
782 explicit NoAlias (X x, Y y, Z z) : ArrayClass (x, y, z) { } 782 explicit NoAlias (X x, Y y, Z z) : ArrayClass (x, y, z) { }
783 783
784 T& operator () (octave_idx_type n) 784 T& operator () (octave_idx_type n)
785 { return ArrayClass::xelem (n); } 785 { return ArrayClass::xelem (n); }
786 T& operator () (octave_idx_type i, octave_idx_type j) 786 T& operator () (octave_idx_type i, octave_idx_type j)
789 { return ArrayClass::xelem (i, j, k); } 789 { return ArrayClass::xelem (i, j, k); }
790 T& operator () (const Array<octave_idx_type>& ra_idx) 790 T& operator () (const Array<octave_idx_type>& ra_idx)
791 { return ArrayClass::xelem (ra_idx); } 791 { return ArrayClass::xelem (ra_idx); }
792 }; 792 };
793 793
794 template <class T> 794 template <typename T>
795 std::ostream& 795 std::ostream&
796 operator << (std::ostream& os, const Array<T>& a); 796 operator << (std::ostream& os, const Array<T>& a);
797 797
798 #endif 798 #endif