Teuchos - Trilinos Tools Package  Version of the Day
Teuchos_Array.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_ARRAY_H
43 #define TEUCHOS_ARRAY_H
44 
49 #include "Teuchos_ConfigDefs.hpp"
50 #include "Teuchos_Assert.hpp"
52 #include "Teuchos_ArrayRCP.hpp"
53 #include "Teuchos_Tuple.hpp"
54 #include "Teuchos_Utils.hpp"
55 #include "Teuchos_Assert.hpp"
56 
57 #if defined(HAVE_TEUCHOSCORE_CXX11) && defined(HAVE_TEUCHOS_ARRAY_BOUNDSCHECK) && defined(HAVE_TEUCHOS_THREAD_SAFE) && !defined(REMOVE_THREAD_PROTECTION_FOR_ARRAY)
58 #include <mutex>
59 #define USE_MUTEX_LOCK_FOR_ARRAY
60 #endif
61 
62 namespace Teuchos {
63 
68 class InvalidArrayStringRepresentation : public std::logic_error
69 {public:InvalidArrayStringRepresentation(const std::string& what_arg) : std::logic_error(what_arg) {}};
70 
71 
72 template<typename T> class Array;
73 
74 
75 // 2007/11/30: rabartl: Below, I had to move the initial declaration of these
76 // non-member template functions outside of the Array class since the Sun
77 // compiler on sass9000 would not accept this. However, this did work on a
78 // number of other compilers such a g++, Intel C++ etc. The old in-class
79 // non-member friend definition is clearly ISO 98 C++ as shown in Item 46 of
80 // "Effective C++: Third Edition". This is not the end of the world but this
81 // is something to remember for this platform.
82 
83 
88 template<typename T> inline
89 bool operator==( const Array<T> &a1, const Array<T> &a2 );
90 
91 
96 template<typename T> inline
97 bool operator!=( const Array<T> &a1, const Array<T> &a2 );
98 
99 
104 template<typename T> inline
105 void swap( Array<T> &a1, Array<T> &a2 );
106 
107 
112 template<typename T> inline
113 bool operator<( const Array<T> &a1, const Array<T> &a2 );
114 
115 
120 template<typename T> inline
121 bool operator<=( const Array<T> &a1, const Array<T> &a2 );
122 
123 
128 template<typename T> inline
129 bool operator>( const Array<T> &a1, const Array<T> &a2 );
130 
131 
136 template<typename T> inline
137 bool operator>=( const Array<T> &a1, const Array<T> &a2 );
138 
139 
193 template<typename T>
194 class Array
195 {
196 public:
197 
198  // 2007/11/30: rabartl: Below, note that the only reason that these
199  // functions are declared as friends is so that the compiler will do
200  // automatic type conversions as described in "Effective C++: Third Edition"
201  // Item 46.
202 
204  template<typename T2>
205  friend bool Teuchos::operator==( const Array<T2> &a1, const Array<T2> &a2 );
206 
208  template<typename T2>
209  friend bool Teuchos::operator!=( const Array<T2> &a1, const Array<T2> &a2 );
210 
212  template<typename T2>
213  friend void swap( Array<T2> &a1, Array<T2> &a2 );
214 
216  template<typename T2>
217  friend bool Teuchos::operator<( const Array<T2> &a1, const Array<T2> &a2 );
218 
220  template<typename T2>
221  friend bool Teuchos::operator<=( const Array<T2> &a1, const Array<T2> &a2 );
222 
224  template<typename T2>
225  friend bool Teuchos::operator>( const Array<T2> &a1, const Array<T2> &a2 );
226 
228  template<typename T2>
229  friend bool Teuchos::operator>=( const Array<T2> &a1, const Array<T2> &a2 );
230 
233 
235  typedef Teuchos_Ordinal Ordinal;
241  typedef typename std::vector<T>::value_type value_type;
243  typedef typename std::vector<T>::pointer pointer;
245  typedef typename std::vector<T>::const_pointer const_pointer;
247  typedef typename std::vector<T>::reference reference;
249  typedef typename std::vector<T>::const_reference const_reference;
251  typedef typename std::vector<T>::allocator_type allocator_type;
252 
253 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
254  typedef ArrayRCP<T> iterator;
259  typedef std::reverse_iterator<iterator> reverse_iterator;
261  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
262 #else
263  typedef typename std::vector<T>::iterator iterator;
266  typedef typename std::vector<T>::const_iterator const_iterator;
268  typedef typename std::vector<T>::reverse_iterator reverse_iterator;
270  typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
271 #endif
272 
274 
276 
278  inline Array();
279 
281  inline explicit Array(size_type n, const value_type& value = value_type());
282 
284  inline Array(const Array<T>& x);
285 
287  template<typename InputIterator>
288  inline Array(InputIterator first, InputIterator last);
289 
291  inline Array(const ArrayView<const T>& a);
292 
294  template<int N>
295  inline Array(const Tuple<T,N>& t);
296 
298  inline ~Array();
299 
301  inline Array& operator=(const Array<T>& a);
302 
304 
310 
312  inline void assign(size_type n, const value_type& val);
314  template<typename InputIterator>
315  inline void assign(InputIterator first, InputIterator last);
317  inline iterator begin();
319  inline iterator end();
321  inline const_iterator begin() const;
323  inline const_iterator end() const;
325  inline reverse_iterator rbegin();
327  inline reverse_iterator rend();
329  inline const_reverse_iterator rbegin() const;
331  inline const_reverse_iterator rend() const;
333  inline size_type size() const;
335  inline size_type max_size() const;
337  inline void resize(size_type new_size, const value_type& x = value_type());
339  inline size_type capacity() const;
341  inline bool empty() const;
343  inline void reserve(size_type n);
345  inline reference operator[](size_type i);
347  inline const_reference operator[](size_type i) const;
349  inline reference at(size_type i);
351  inline const_reference at(size_type i) const;
353  inline reference front();
355  inline const_reference front() const;
357  inline reference back();
359  inline const_reference back() const;
361  inline void push_back(const value_type& x);
363  inline void pop_back();
365  inline iterator insert(iterator position, const value_type& x);
367  inline void insert(iterator position, size_type n, const value_type& x);
369  template<typename InputIterator>
370  inline void insert(iterator position, InputIterator first, InputIterator last);
372  inline iterator erase(iterator position);
374  inline iterator erase(iterator first, iterator last);
376  inline void swap(Array& x);
378  inline void clear();
379 
381 
383 
388  inline Array<T>& append(const T& x);
389 
393  inline void remove(int i);
394 
399  inline int length() const;
400 
402  inline std::string toString() const;
403 
405  inline static bool hasBoundsChecking();
406 
408  inline T* getRawPtr();
409 
411  inline const T* getRawPtr() const;
412 
414 
416 
418  inline Array( const std::vector<T> &v );
419 
421  inline std::vector<T> toVector() const;
422 
424  inline Array& operator=( const std::vector<T> &v );
425 
427 
429 
430 
444  inline ArrayView<T> view( size_type offset, size_type size );
445 
459  inline ArrayView<const T> view( size_type offset, size_type size ) const;
460 
464  inline ArrayView<T> operator()( size_type offset, size_type size );
465 
469  inline ArrayView<const T> operator()( size_type offset, size_type size ) const;
470 
475  inline ArrayView<T> operator()();
476 
481  inline ArrayView<const T> operator()() const;
482 
486  inline operator ArrayView<T>();
487 
491  inline operator ArrayView<const T>() const;
492 
494 
495 private:
496 
497 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
498  RCP<std::vector<T> > vec_;
499  mutable ArrayRCP<T> extern_arcp_;
500  mutable ArrayRCP<const T> extern_carcp_;
501 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
502  mutable std::mutex mutex_lock; // this mutex provides thread safe debugging for the vec_, extern_arcp_, extern_carcp_
503 #endif
504 #else
505  std::vector<T> vec_;
506 #endif
507 
508  inline std::vector<T>& vec(
509  bool isStructureBeingModified = false,
510  bool activeIter = false
511  );
512 
513  inline const std::vector<T>& vec() const;
514 
515  inline typename std::vector<T>::iterator
516  raw_position( iterator position );
517 
518  inline void assertIndex(size_type i) const;
519 
520  inline void assertNotNull() const;
521 
522 };
523 
524 
530 template<class T>
532 {
533  if ( is_null(v) || !v->size() )
534  return null;
535  return arcpWithEmbeddedObjPostDestroy<T,RCP<Array<T> > >(
536  &(*v)[0], 0, v->size(),
537  v, false
538  );
539 }
540 
541 
547 template<class T>
548 ArrayRCP<const T> arcp( const RCP<const Array<T> > &v )
549 {
550  if ( is_null(v) || !v->size() )
551  return null;
552  return arcpWithEmbeddedObjPostDestroy<const T,RCP<const Array<T> > >(
553  &(*v)[0], 0, v->size(),
554  v, false
555  );
556 }
557 
558 
564 template<class T>
566 {
567  if (a.size() == 0)
568  return null;
569 #ifdef TEUCHOS_DEBUG
570  return a.begin(); // Catch dangling reference!
571 #else
572  return arcp(a.getRawPtr(), 0, a.size(), false);
573 #endif
574 }
575 
576 
582 template<class T>
584 {
585  if (a.size() == 0)
586  return null;
587 #ifdef TEUCHOS_DEBUG
588  return a.begin(); // Catch dangling reference!
589 #else
590  return arcp(a.getRawPtr(), 0, a.size(), false);
591 #endif
592 }
593 
594 
607 template<typename T>
608 std::ostream& operator<<(std::ostream& os, const Array<T>& array);
609 
610 
615 template<typename T> inline
616 int hashCode(const Array<T>& array);
617 
618 
625 template<typename T> inline
626 std::vector<T> createVector( const Array<T> &a );
627 
628 
633 template<typename T>
634 std::string toString(const Array<T>& array);
635 
636 
688 template<typename T>
689 Array<T> fromStringToArray(const std::string& arrayStr);
690 
696 template<typename T>
697 std::istringstream& operator>> (std::istringstream& in, Array<T>& array){
698  array = fromStringToArray<T>(in.str());
699  return in;
700 }
701 
707 template<typename T> inline
708 void extractDataFromISS( std::istringstream& iss, T& data )
709 {
710  iss >> data; // Assumes type has operator>>(...) defined!
711 }
712 
719 inline
720 void extractDataFromISS( std::istringstream& iss, std::string& data )
721 {
722  // grab unformatted string.
723  data = iss.str();
724  // remove white space from beginning and end of string.
725  data = Utils::trimWhiteSpace(data);
726 }
727 
737 inline
739  return "Array(*)";
740 }
741 
742 
743 
759 template<typename T>
760 class TEUCHOSCORE_LIB_DLL_EXPORT TypeNameTraits<Array<T> > {
761 public:
762  static std::string name(){
763  std::string formatString = getArrayTypeNameTraitsFormat();
764  size_t starPos = formatString.find("*");
765  std::string prefix = formatString.substr(0,starPos);
766  std::string postFix = formatString.substr(starPos+1);
767  return prefix+TypeNameTraits<T>::name()+postFix;
768  }
769  static std::string concreteName(const Array<T>&)
770  { return name(); }
771 };
772 
773 
774 } // namespace Teuchos
775 
776 
777 //
778 // Implementation
779 //
780 
781 
782 namespace Teuchos {
783 
784 
785 // All constructors
786 
787 
788 template<typename T> inline
790 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
791  : vec_(rcp(new std::vector<T>()))
792 #endif
793 {}
794 
795 
796 template<typename T> inline
798 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
799  vec_(rcp(new std::vector<T>(n,value)))
800 #else
801  vec_(n, value)
802 #endif
803 {}
804 
805 
806 template<typename T> inline
808 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
809  vec_(rcp(new std::vector<T>(*x.vec_)))
810 #else
811  vec_(x.vec_)
812 #endif
813 {}
814 
815 
816 template<typename T> template<typename InputIterator> inline
817 Array<T>::Array(InputIterator first, InputIterator last) :
818 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
819  vec_(rcp(new std::vector<T>(first, last)))
820 #else
821  vec_(first, last)
822 #endif
823 {}
824 
825 
826 template<typename T> inline
828 {}
829 
830 
831 template<typename T> inline
833 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
834  : vec_(rcp(new std::vector<T>()))
835 #endif
836 {
837  insert(begin(), a.begin(), a.end());
838 }
839 
840 
841 template<typename T>
842 template<int N>
843 inline
845 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
846  : vec_(rcp(new std::vector<T>()))
847 #endif
848 {
849  insert(begin(), t.begin(), t.end());
850 }
851 
852 
853 template<typename T> inline
855 {
856 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
857  std::lock_guard<std::mutex> lockGuard(mutex_lock);
858 #endif
859  vec(true) = a.vec();
860  return *this;
861 }
862 
863 
864 // Other std::vector functions
865 
866 
867 template<typename T> inline
869 {
870 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
871  std::lock_guard<std::mutex> lockGuard(mutex_lock);
872 #endif
873  vec(true).assign(n,val);
874 }
875 
876 
877 template<typename T> template<typename InputIterator> inline
878 void Array<T>::assign(InputIterator first, InputIterator last)
879 {
880 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
881  std::lock_guard<std::mutex> lockGuard(mutex_lock);
882 #endif
883  vec(true).assign(first,last);
884 }
885 
886 
887 template<typename T> inline
888 typename Array<T>::iterator
890 {
891 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
892 
893 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
894  std::lock_guard<std::mutex> lockGuard(mutex_lock);
895 #endif
896 
897  if (is_null(extern_arcp_)) {
898  // Here we must use the same RCP to avoid creating two unrelated RCPNodes!
899  extern_arcp_ = arcp(vec_); // Will be null if vec_ is sized!
900  }
901  // Returning a weak pointer will help to catch dangling references but still
902  // keep the same behavior as optimized code.
903 
904  return extern_arcp_.create_weak();
905 #else
906  return vec().begin();
907 #endif
908 }
909 
910 
911 template<typename T> inline
912 typename Array<T>::iterator
914 {
915 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
916  return begin() + size();
917 #else
918  return vec().end();
919 #endif
920 }
921 
922 template<typename T> inline
925 {
926 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
927 
928 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
929  std::lock_guard<std::mutex> lockGuard(mutex_lock);
930 #endif
931  if (is_null(extern_carcp_)) {
932  // Note that this used to call the non-const begin() function above
933  // I've moved that code here to make the mutex locking more transparent and
934  // prevent the need to structure something awkward to avoid double locks
935  // The original line of code was this:
936  // extern_carcp_ = const_cast<Array<T>*>(this)->begin();
937  // Now replaced by the following code which mirrors the above begin() call
938  if (is_null(extern_arcp_)) {
939  extern_arcp_ = arcp(vec_);
940  }
941  // note that we call create_weak() twice, first on the non-const and then
942  // below on the const - this preserves the original design exactly
943  extern_carcp_ = extern_arcp_.create_weak();
944  }
945 
946  // Returning a weak pointer will help to catch dangling references but still
947  // keep the same behavior as optimized code.
948  return extern_carcp_.create_weak();
949 #else
950  return vec().begin();
951 #endif
952 }
953 
954 
955 template<typename T> inline
958 {
959 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
960  return begin() + size();
961 #else
962  return vec().end();
963 #endif
964 }
965 
966 
967 template<typename T> inline
970 {
971 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
972  return reverse_iterator(end());
973 #else
974  return vec().rbegin();
975 #endif
976 }
977 
978 
979 template<typename T> inline
982 {
983 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
984  return reverse_iterator(begin());
985 #else
986  return vec().rend();
987 #endif
988 }
989 
990 
991 template<typename T> inline
994 {
995 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
996  return const_reverse_iterator(end());
997 #else
998  return vec().rbegin();
999 #endif
1000 }
1001 
1002 
1003 template<typename T> inline
1006 {
1007 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1008  return const_reverse_iterator(begin());
1009 #else
1010  return vec().rend();
1011 #endif
1012 }
1013 
1014 
1015 template<typename T> inline
1016 typename Array<T>::size_type
1018 {
1019  return vec().size();
1020 }
1021 
1022 
1023 template<typename T> inline
1024 typename Array<T>::size_type
1026 {
1027  return std::numeric_limits<size_type>::max();
1028 }
1029 
1030 
1031 template<typename T> inline
1032 void
1034 {
1035 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1036  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1037 #endif
1038  vec(true).resize(new_size,x);
1039 }
1040 
1041 
1042 template<typename T> inline
1043 typename Array<T>::size_type
1045 {
1046  return vec().capacity();
1047 }
1048 
1049 
1050 template<typename T> inline
1051 bool Array<T>::empty() const
1052 {
1053  return vec().empty();
1054 }
1055 
1056 
1057 template<typename T> inline
1059 {
1060 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1061  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1062 #endif
1063  vec(true).reserve(n);
1064 }
1065 
1066 
1067 template<typename T> inline
1068 typename Array<T>::reference
1070 {
1071 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1072  assertIndex(i);
1073 #endif
1074  return vec()[i];
1075 }
1076 
1077 
1078 template<typename T> inline
1081 {
1082 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1083  assertIndex(i);
1084 #endif
1085  return vec()[i];
1086 }
1087 
1088 
1089 template<typename T> inline
1090 typename Array<T>::reference
1092 {
1093 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1094  assertIndex(i);
1095 #endif
1096  return vec().at(i);
1097 }
1098 
1099 
1100 template<typename T> inline
1103 {
1104 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1105  assertIndex(i);
1106 #endif
1107  return vec().at(i);
1108 }
1109 
1110 
1111 template<typename T> inline
1112 typename Array<T>::reference
1114 {
1115 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1116  assertNotNull();
1117 #endif
1118  return vec().front();
1119 }
1120 
1121 
1122 template<typename T> inline
1125 {
1126 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1127  assertNotNull();
1128 #endif
1129  return vec().front();
1130 }
1131 
1132 
1133 template<typename T> inline
1134 typename Array<T>::reference
1136 {
1137 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1138  assertNotNull();
1139 #endif
1140  return vec().back();
1141 }
1142 
1143 
1144 template<typename T> inline
1147 {
1148 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1149  assertNotNull();
1150 #endif
1151  return vec().back();
1152 }
1153 
1154 
1155 template<typename T> inline
1157 {
1158 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1159  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1160 #endif
1161  vec(true).push_back(x);
1162 }
1163 
1164 
1165 template<typename T> inline
1167 {
1168 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1169  assertNotNull();
1170 #endif
1171 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1172  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1173 #endif
1174  vec(true).pop_back();
1175 }
1176 
1177 
1178 // 2009/11/13:: rabartl: After moving to a full RCPNode tracing and lookup
1179 // model, I had to how modifying functions like insert(...) and erase(...)
1180 // work which have active iterators controled by the client and yet need to
1181 // allow the structure of the container change. The way these troublesome
1182 // functions work is that first the raw std::vector iterator is extracted.
1183 // The function vec(true, true) then deletes the strong iterators but there is
1184 // still a weak ArrayRCP object that is owned by the client which is being
1185 // passed into this function. The issue is that the design of ArrayRCP is
1186 // such that the RCPNode object is not removed but instead remains in order to
1187 // perform runtime checking.
1188 
1189 
1190 template<typename T> inline
1191 typename Array<T>::iterator
1193 {
1194 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1195  // Assert a valid iterator and get vector iterator
1196  const typename std::vector<T>::iterator raw_poss = raw_position(position);
1197  const difference_type i = position - begin();
1198 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1199  {
1200  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1201 #endif
1202  vec(true, true).insert(raw_poss, x);
1203 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1204  } // must unlock mutex_lock before calling begin() which will lock again
1205 #endif
1206  return begin() + i;
1207 #else
1208  return vec_.insert(position, x);
1209 #endif
1210 }
1211 
1212 
1213 template<typename T> inline
1214 void Array<T>::insert(iterator position, size_type n, const value_type& x)
1215 {
1216 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1217  const typename std::vector<T>::iterator raw_poss = raw_position(position);
1218 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1219  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1220 #endif
1221  vec(true, true).insert(raw_poss, n, x);
1222 #else
1223  vec_.insert(position, n, x);
1224 #endif
1225 }
1226 
1227 
1228 template<typename T> template<typename InputIterator> inline
1229 void Array<T>::insert(iterator position, InputIterator first, InputIterator last)
1230 {
1231 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1232  const typename std::vector<T>::iterator raw_poss = raw_position(position);
1233 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1234  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1235 #endif
1236  vec(true, true).insert(raw_poss, first, last);
1237 #else
1238  vec_.insert(position, first, last);
1239 #endif
1240 }
1241 
1242 
1243 template<typename T> inline
1244 typename Array<T>::iterator
1246 {
1247 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1248  assertNotNull();
1249  // Assert a valid iterator and get vector iterator
1250  const typename std::vector<T>::iterator raw_poss = raw_position(position);
1251  const difference_type i = position - begin();
1252 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1253  {
1254  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1255 #endif
1256  vec(true, true).erase(raw_poss);
1257 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1258  } // must unlock mutex_lock before call begin() or dead lock on second call
1259 #endif
1260  return begin() + i;
1261 #else
1262  return vec_.erase(position);
1263 #endif
1264 }
1265 
1266 
1267 template<typename T> inline
1268 typename Array<T>::iterator
1270 {
1271 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1272  if (empty()) {
1273  TEUCHOS_ASSERT(first == begin());
1274  TEUCHOS_ASSERT(last == end());
1275  return end();
1276  }
1277  assertNotNull();
1278  // Assert a valid iterator and get vector iterator
1279  const typename std::vector<T>::iterator raw_first = raw_position(first);
1280  const typename std::vector<T>::iterator raw_last = raw_position(last);
1281  const difference_type i = first - begin();
1282 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1283  {
1284  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1285 #endif
1286  vec(true,true).erase(raw_first,raw_last);
1287 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1288  } // must unlock mutex_lock before call begin() or dead lock on second call
1289 #endif
1290  return begin() + i;
1291 #else
1292  return vec_.erase(first,last);
1293 #endif
1294 }
1295 
1296 
1297 template<typename T> inline
1299 {
1300 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1301  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1302 #endif
1303  vec(true).swap(x.vec());
1304 }
1305 
1306 
1307 template<typename T> inline
1309 {
1310 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1311  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1312 #endif
1313  vec(true).clear();
1314 }
1315 
1316 
1317 // Non-standard functions
1318 
1319 
1320 template<typename T> inline
1322 {
1323  this->push_back(x);
1324  return *this;
1325 }
1326 
1327 
1328 template<typename T> inline
1329 void Array<T>::remove(int i)
1330 {
1331 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1332  assertIndex(i);
1333 #endif
1334  // Erase the i-th element of this array.
1335  this->erase( this->begin() + i );
1336 }
1337 
1338 
1339 template<typename T> inline
1340 int Array<T>::length() const
1341 {
1342  return static_cast<int> (this->size ());
1343 }
1344 
1345 
1346 template<typename T> inline
1347 std::string Array<T>::toString() const
1348 {
1349  return (*this)().toString(); // Use ArrayView<T>::toString()
1350 }
1351 
1352 
1353 template<typename T> inline
1355 {
1356 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1357  return true;
1358 #else
1359  return false;
1360 #endif
1361 }
1362 
1363 
1364 template<typename T> inline
1366 {
1367  return ( size() ? &(*this)[0] : 0 );
1368 }
1369 
1370 
1371 template<typename T> inline
1372 const T* Array<T>::getRawPtr() const
1373 {
1374  return ( size() ? &(*this)[0] : 0 );
1375 }
1376 
1377 
1378 // Conversions to and from std::vector
1379 
1380 
1381 template<typename T> inline
1382 Array<T>::Array( const std::vector<T> &v ) :
1383 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1384  vec_(new std::vector<T>(v))
1385 #else
1386  vec_(v)
1387 #endif
1388 {}
1389 
1390 
1391 template<typename T> inline
1392 std::vector<T> Array<T>::toVector() const
1393 {
1394  if (!size())
1395  return std::vector<T>();
1396  std::vector<T> v(begin(),end());
1397  return v;
1398 }
1399 
1400 
1401 template<typename T> inline
1402 Array<T>& Array<T>::operator=( const std::vector<T> &v )
1403 {
1404 #ifdef USE_MUTEX_LOCK_FOR_ARRAY
1405  std::lock_guard<std::mutex> lockGuard(mutex_lock);
1406 #endif
1407  vec(true) = v;
1408  return *this;
1409 }
1410 
1411 
1412 // Views
1413 
1414 
1415 template<typename T> inline
1417 {
1418  if (size_in) {
1419 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1420  return ArrayView<T>(this->begin().persistingView(offset, size_in));
1421 #else
1422  return arrayView( &vec()[offset], size_in );
1423 #endif
1424  }
1425  return Teuchos::null;
1426 }
1427 
1428 
1429 template<typename T> inline
1431 {
1432  if (size_in) {
1433 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1434  return ArrayView<const T>(this->begin().persistingView(offset, size_in));
1435 #else
1436  return arrayView( &vec()[offset], size_in );
1437 #endif
1438  }
1439  return Teuchos::null;
1440  // NOTE: Above, we use a different implementation to call the const version
1441  // of begin() instead of the non-const version. This sets up a different
1442  // ArrayRCP object that gets checked.
1443 }
1444 
1445 
1446 template<typename T> inline
1448 {
1449  return view(offset, size_in);
1450 }
1451 
1452 
1453 template<typename T> inline
1455 {
1456  return view(offset, size_in);
1457 }
1458 
1459 
1460 template<typename T> inline
1462 {
1463  if (!size())
1464  return null;
1465  return this->view(0, size());
1466 }
1467 
1468 
1469 template<typename T> inline
1471 {
1472  if (!size())
1473  return null;
1474  return this->view(0, size());
1475 }
1476 
1477 
1478 template<typename T> inline
1480 {
1481  return this->operator()();
1482 }
1483 
1484 
1485 template<typename T> inline
1487 {
1488  return this->operator()();
1489 }
1490 
1491 
1492 // private
1493 
1494 
1495 template<typename T>
1496 std::vector<T>&
1497 Array<T>::vec( bool isStructureBeingModified, bool activeIter )
1498 {
1499 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1500  (void)activeIter;
1501  if (isStructureBeingModified) {
1502  // Give up my ArrayRCPs used for iterator access since the array we be
1503  // getting modifed! Any clients that have views through weak pointers
1504  // better not touch them!
1505 
1506  // Note that in debug mode these are mutex protected - the mutex should
1507  // always be locked when this function is called with
1508  // isStructureBeingModified true
1509  extern_arcp_ = null;
1510  extern_carcp_ = null;
1511  }
1512  return *vec_;
1513 #else
1514  // get rid of "unused parameter" warnings
1515  (void)isStructureBeingModified;
1516  (void)activeIter;
1517  return vec_;
1518 #endif
1519 }
1520 
1521 
1522 template<typename T> inline
1523 const std::vector<T>&
1524 Array<T>::vec() const
1525 {
1526 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1527  return *vec_;
1528 #else
1529  return vec_;
1530 #endif
1531 }
1532 
1533 
1534 template<typename T> inline
1535 typename std::vector<T>::iterator
1536 Array<T>::raw_position( iterator position )
1537 {
1538 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1539  const iterator first = this->begin();
1540  const iterator last = this->end();
1542  !(first <= position && position <= last), DanglingReferenceError,
1543  "Error, this iterator is no longer valid for this Aray!"
1544  );
1545  // Note, above operator<=(...) functions will throw
1546  // IncompatibleIteratorsError if the iterators do not share the same
1547  // RCP_node object!
1548  return vec_->begin() + (position - this->begin());
1549 #else
1550  return position;
1551 #endif
1552 }
1553 
1554 
1555 template<typename T> inline
1556 void Array<T>::assertIndex(size_type i) const
1557 {
1559  !( 0 <= i && i < size() ), RangeError,
1560  "Array<T>::assertIndex(i): i="<<i<<" out of range [0, "<< size() << ")"
1561  );
1562 }
1563 
1564 
1565 template<typename T> inline
1566 void Array<T>::assertNotNull() const
1567 {
1569  !size(), NullReferenceError,
1570  typeName(*this)<<"::assertNotNull(): "
1571  "Error, the array has size zero!"
1572  );
1573 }
1574 
1575 
1576 } // namespace Teuchos
1577 
1578 
1579 // Nonmember functions
1580 
1581 
1582 template<typename T> inline
1583 bool Teuchos::operator==( const Array<T> &a1, const Array<T> &a2 )
1584 { return (a1.vec() == a2.vec()); }
1585 
1586 
1587 template<typename T> inline
1588 bool Teuchos::operator!=( const Array<T> &a1, const Array<T> &a2 )
1589 { return (a1.vec() != a2.vec()); }
1590 
1591 
1592 template<typename T> inline
1593 void Teuchos::swap( Array<T> &a1, Array<T> &a2 )
1594 { a1.swap(a2); }
1595 
1596 
1597 template<typename T> inline
1598 bool Teuchos::operator<( const Array<T> &a1, const Array<T> &a2 )
1599 { return (a1.vec() < a2.vec()); }
1600 
1601 
1602 template<typename T> inline
1603 bool Teuchos::operator<=( const Array<T> &a1, const Array<T> &a2 )
1604 { return (a1.vec() <= a2.vec()); }
1605 
1606 
1607 template<typename T> inline
1608 bool Teuchos::operator>( const Array<T> &a1, const Array<T> &a2 )
1609 { return (a1.vec() > a2.vec()); }
1610 
1611 
1612 template<typename T> inline
1613 bool Teuchos::operator>=( const Array<T> &a1, const Array<T> &a2 )
1614 { return (a1.vec() >= a2.vec()); }
1615 
1616 
1617 template<typename T> inline
1618 std::ostream& Teuchos::operator<<(
1619  std::ostream& os, const Array<T>& array
1620  )
1621 {
1622  return os << Teuchos::toString(array);
1623 }
1624 
1625 
1626 template<typename T> inline
1627 int Teuchos::hashCode(const Array<T>& array)
1628 {
1629  int rtn = hashCode(array.length());
1630  for (int i=0; i<array.length(); i++)
1631  {
1632  rtn += hashCode(array[i]);
1633  }
1634  if (rtn < 0)
1635  {
1636  /* Convert the largest -ve int to zero and -1 to
1637  * std::numeric_limits<int>::max()
1638  * */
1639  size_t maxIntBeforeWrap = std::numeric_limits<int>::max();
1640  maxIntBeforeWrap ++;
1641  rtn += maxIntBeforeWrap;
1642  }
1643  return rtn;
1644 }
1645 
1646 
1647 template<typename T> inline
1648 std::vector<T> Teuchos::createVector( const Array<T> &a )
1649 {
1650  return a.toVector();
1651 }
1652 
1653 
1654 template<typename T> inline
1655 std::string Teuchos::toString(const Array<T>& array)
1656 {
1657  return array.toString();
1658 }
1659 
1660 
1661 template<typename T>
1663 Teuchos::fromStringToArray(const std::string& arrayStr)
1664 {
1665  const std::string str = Utils::trimWhiteSpace(arrayStr);
1666  std::istringstream iss(str);
1668  ( str[0]!='{' || str[str.length()-1] != '}' )
1669  ,InvalidArrayStringRepresentation
1670  ,"Error, the std::string:\n"
1671  "----------\n"
1672  <<str<<
1673  "\n----------\n"
1674  "is not a valid array represntation!"
1675  );
1676  char c;
1677  c = iss.get(); // Read initial '{'
1678  TEUCHOS_TEST_FOR_EXCEPT(c!='{'); // Should not throw!
1679  // Now we are ready to begin reading the entries of the array!
1680  Array<T> a;
1681  while( !iss.eof() ) {
1682  // Get the basic entry std::string
1683  std::string entryStr;
1684  std::getline(iss,entryStr,','); // Get next entry up to ,!
1685  // ToDo: Above, we might have to be careful to look for the opening and
1686  // closing of parentheses in order not to pick up an internal ',' in the
1687  // middle of an entry (for a std::complex number for instance). The above
1688  // implementation assumes that there will be no commas in the middle of
1689  // the std::string representation of an entry. This is certainly true for
1690  // the types bool, int, float, and double.
1691  //
1692  // Trim whitespace from beginning and end
1693  entryStr = Utils::trimWhiteSpace(entryStr);
1695  0 == entryStr.length(),
1696  InvalidArrayStringRepresentation,
1697  "Error, the std::string:\n"
1698  "----------\n"
1699  <<str<<
1700  "\n----------\n"
1701  "is not a valid array represntation because it has an empty array entry!"
1702  );
1703  // Remove the final '}' if this is the last entry and we did not
1704  // actually terminate the above getline(...) on ','
1705  bool found_end = false;
1706  if(entryStr[entryStr.length()-1]=='}') {
1707  entryStr = entryStr.substr(0,entryStr.length()-1);
1708  found_end = true;
1709  if( entryStr.length()==0 && a.size()==0 )
1710  return a; // This is the empty array "{}" (with any spaces in it!)
1711  }
1712  // Finally we can convert the entry and add it to the array!
1713  std::istringstream entryiss(entryStr);
1714  T entry;
1715  Teuchos::extractDataFromISS( entryiss, entry );
1716  // ToDo: We may need to define a traits class to allow us to specialized
1717  // how conversion from a std::string to a object is done!
1718  a.push_back(entry);
1719  // At the end of the loop body here, if we have reached the last '}'
1720  // then the input stream iss should be empty and iss.eof() should be
1721  // true, so the loop should terminate. We put an std::exception test here
1722  // just in case something has gone wrong.
1724  found_end && !iss.eof()
1725  ,InvalidArrayStringRepresentation
1726  ,"Error, the std::string:\n"
1727  "----------\n"
1728  <<str<<
1729  "\n----------\n"
1730  "is not a valid array represntation!"
1731  );
1732  }
1733  return a;
1734 }
1735 
1736 
1737 #endif // TEUCHOS_ARRAY_H
Teuchos::TypeNameTraits::name
static std::string name()
Definition: Teuchos_TypeNameTraits.hpp:88
Teuchos::Array::front
reference front()
Definition: Teuchos_Array.hpp:1113
Teuchos::Array::getArrayTypeNameTraitsFormat
std::string getArrayTypeNameTraitsFormat()
Get the format that is used for the specialization of the TypeName traits class for Array.
Definition: Teuchos_Array.hpp:738
TEUCHOS_TEST_FOR_EXCEPT
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
Definition: Teuchos_TestForException.hpp:307
Teuchos::Array::size
size_type size() const
Definition: Teuchos_Array.hpp:1017
Teuchos::Array::pointer
std::vector< T >::pointer pointer
The type of a pointer to T; for compatibility with std::vector.
Definition: Teuchos_Array.hpp:243
Teuchos::Array::end
iterator end()
Definition: Teuchos_Array.hpp:913
Teuchos::Array::const_iterator
std::vector< T >::const_iterator const_iterator
The type of a const forward iterator.
Definition: Teuchos_Array.hpp:266
Teuchos::Array::capacity
size_type capacity() const
Definition: Teuchos_Array.hpp:1044
Teuchos::Array::rbegin
reverse_iterator rbegin()
Definition: Teuchos_Array.hpp:969
Teuchos::Array::const_reference
std::vector< T >::const_reference const_reference
The type of a const reference to T; for compatibility with std::vector.
Definition: Teuchos_Array.hpp:249
Teuchos::Array::resize
void resize(size_type new_size, const value_type &x=value_type())
Definition: Teuchos_Array.hpp:1033
Teuchos::Array::back
reference back()
Definition: Teuchos_Array.hpp:1135
Teuchos::Array::swap
friend void swap(Array< T2 > &a1, Array< T2 > &a2)
Teuchos::Tuple
Statically sized simple array (tuple) class.
Definition: Teuchos_Tuple.hpp:67
Teuchos::Array::Ordinal
Teuchos_Ordinal Ordinal
The type of indices.
Definition: Teuchos_Array.hpp:235
Teuchos::Array::reference
std::vector< T >::reference reference
The type of a reference to T; for compatibility with std::vector.
Definition: Teuchos_Array.hpp:247
Teuchos::Array::extractDataFromISS
void extractDataFromISS(std::istringstream &iss, T &data)
Extracts data from an istringstream object.
Definition: Teuchos_Array.hpp:708
Teuchos::ArrayRCP::is_null
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
Teuchos::RCP::rcp
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object.
Teuchos::Array::toString
std::string toString() const
Convert an Array to an std::string
Definition: Teuchos_Array.hpp:1347
Teuchos::Array::empty
bool empty() const
Definition: Teuchos_Array.hpp:1051
Teuchos::Array::max_size
size_type max_size() const
Definition: Teuchos_Array.hpp:1025
Teuchos::ArrayRCP::arcp
ArrayRCP< const T > arcp(const RCP< const Array< T > > &v)
Wrap a RCP<const Array<T> > object as an ArrayRCP<const T> object.
Definition: Teuchos_Array.hpp:548
Teuchos::ArrayRCP::arcpFromArray
ArrayRCP< T > arcpFromArray(Array< T > &a)
Wrap an Array<T> object as a non-owning ArrayRCP<T> object.
Definition: Teuchos_Array.hpp:565
Teuchos::Array::allocator_type
std::vector< T >::allocator_type allocator_type
The allocator type; for compatibility with std::vector.
Definition: Teuchos_Array.hpp:251
Teuchos::Array::push_back
void push_back(const value_type &x)
Definition: Teuchos_Array.hpp:1156
Teuchos_Utils.hpp
A utilities class for Teuchos.
Teuchos::TypeNameTraits
Default traits class that just returns typeid(T).name().
Definition: Teuchos_TypeNameTraits.hpp:85
TEUCHOS_ASSERT
#define TEUCHOS_ASSERT(assertion_test)
This macro is throws when an assert fails.
Definition: Teuchos_Assert.hpp:55
Teuchos::Array::const_reverse_iterator
std::vector< T >::const_reverse_iterator const_reverse_iterator
The type of a const reverse iterator.
Definition: Teuchos_Array.hpp:270
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition: Teuchos_RCPDecl.hpp:1224
Teuchos::Array::operator!=
friend bool Teuchos::operator!=(const Array< T2 > &a1, const Array< T2 > &a2)
Teuchos::typeName
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Definition: Teuchos_TypeNameTraits.hpp:115
Teuchos::Array::Array
Array()
Default constructor; creates an empty Array.
Definition: Teuchos_Array.hpp:789
Teuchos::Array::iterator
std::vector< T >::iterator iterator
The type of a forward iterator.
Definition: Teuchos_Array.hpp:264
Teuchos::Array::operator()
ArrayView< T > operator()()
Return an non-const ArrayView of *this.
Definition: Teuchos_Array.hpp:1461
Teuchos::Array::insert
iterator insert(iterator position, const value_type &x)
Definition: Teuchos_Array.hpp:1192
Teuchos::ArrayView
Nonowning array view.
Definition: Teuchos_ArrayViewDecl.hpp:123
Teuchos::Array::at
reference at(size_type i)
Definition: Teuchos_Array.hpp:1091
Teuchos::ArrayRCP::arcp
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
Definition: Teuchos_Array.hpp:531
Teuchos::InvalidArrayStringRepresentation
Definition: Teuchos_Array.hpp:68
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition: Teuchos_RCPDecl.hpp:429
Teuchos::Comm::size
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Teuchos::Array::~Array
~Array()
Destructor.
Definition: Teuchos_Array.hpp:827
Teuchos::Array::operator[]
reference operator[](size_type i)
Definition: Teuchos_Array.hpp:1069
Teuchos::Array::assign
void assign(size_type n, const value_type &val)
Definition: Teuchos_Array.hpp:868
Teuchos::Array
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Definition: Teuchos_Array.hpp:72
Teuchos::ArrayRCP::arcpFromArray
ArrayRCP< const T > arcpFromArray(const Array< T > &a)
Wrap a const Array<T> object as a non-owning ArrayRCP<T> object.
Definition: Teuchos_Array.hpp:583
Teuchos::ArrayView::begin
iterator begin() const
Return an iterator to beginning of the array of data.
Definition: Teuchos_ArrayView.hpp:465
Teuchos::Array::begin
iterator begin()
Definition: Teuchos_Array.hpp:889
Teuchos::Array::reverse_iterator
std::vector< T >::reverse_iterator reverse_iterator
The type of a reverse iterator.
Definition: Teuchos_Array.hpp:268
Teuchos::Array::reserve
void reserve(size_type n)
Definition: Teuchos_Array.hpp:1058
Teuchos::ArrayRCP
Reference-counted smart pointer for managing arrays.
Definition: Teuchos_ArrayRCPDecl.hpp:127
Teuchos::ArrayRCP< const T >
Partial specialization of ArrayRCP for const T.
Definition: Teuchos_ArrayRCPDecl.hpp:845
Teuchos::Array::hashCode
int hashCode(const Array< T > &array)
Return the hash code.
Teuchos::any::toString
std::string toString(const any &rhs)
Converts the value in any to a std::string.
Definition: Teuchos_any.hpp:398
Teuchos::Array::pop_back
void pop_back()
Definition: Teuchos_Array.hpp:1166
Teuchos::Array::rend
reverse_iterator rend()
Definition: Teuchos_Array.hpp:981
Teuchos::Array::remove
void remove(int i)
Remove the i-th element from the array, with optional boundschecking.
Definition: Teuchos_Array.hpp:1329
Teuchos_TypeNameTraits.hpp
Defines basic traits returning the name of a type in a portable and readable way.
Teuchos_ConfigDefs.hpp
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Teuchos::Array::append
Array< T > & append(const T &x)
Add a new entry at the end of the array.
Definition: Teuchos_Array.hpp:1321
Teuchos::Array::view
ArrayView< T > view(size_type offset, size_type size)
Return non-const view of a contiguous range of elements.
Definition: Teuchos_Array.hpp:1416
Teuchos::Array::extractDataFromISS
void extractDataFromISS(std::istringstream &iss, std::string &data)
Extracts std::string data from an istringstream object.
Definition: Teuchos_Array.hpp:720
Teuchos::Array::hasBoundsChecking
static bool hasBoundsChecking()
Return true if Array has been compiled with boundschecking on.
Definition: Teuchos_Array.hpp:1354
Teuchos::Array::erase
iterator erase(iterator position)
Definition: Teuchos_Array.hpp:1245
Teuchos::Array::toVector
std::vector< T > toVector() const
Explicit copy conversion to an std::vector.
Definition: Teuchos_Array.hpp:1392
Teuchos::ArrayView::end
iterator end() const
Return an iterator to past the end of the array of data.
Definition: Teuchos_ArrayView.hpp:488
Teuchos::Array::operator=
Array & operator=(const Array< T > &a)
Assignment operator (does a deep copy).
Definition: Teuchos_Array.hpp:854
Teuchos::Array::getRawPtr
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
Definition: Teuchos_Array.hpp:1365
Teuchos::Array::value_type
std::vector< T >::value_type value_type
The type of an entry of the Array; for compatibility with std::vector.
Definition: Teuchos_Array.hpp:241
Teuchos::Array::const_pointer
std::vector< T >::const_pointer const_pointer
The type of a const pointer to T; for compatibility with std::vector.
Definition: Teuchos_Array.hpp:245
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Teuchos::Array::clear
void clear()
Definition: Teuchos_Array.hpp:1308
Teuchos::ArrayView< const T >
Partial specialization of ArrayView for const T.
Definition: Teuchos_ArrayViewDecl.hpp:428
Teuchos::ArrayView::arrayView
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
Teuchos::Array::size_type
Ordinal size_type
The type of Array sizes and capacities.
Definition: Teuchos_Array.hpp:237
Teuchos::Array::length
int length() const
Return number of elements in the array.
Definition: Teuchos_Array.hpp:1340
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Definition: Teuchos_TestForException.hpp:170
Teuchos::Array::difference_type
Ordinal difference_type
The type of the difference between two size_type values.
Definition: Teuchos_Array.hpp:239
Teuchos::is_null
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
Definition: Teuchos_RCPStdSharedPtrConversionsDecl.hpp:148
Teuchos::Utils::trimWhiteSpace
static std::string trimWhiteSpace(const std::string &str)
Trim whitespace from beginning and end of std::string.
Definition: Teuchos_Utils.cpp:55