Chemical Data Processing Library C++ API - Version 1.2.0
Vector.hpp
Go to the documentation of this file.
1 /*
2  * Vector.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_VECTOR_HPP
28 #define CDPL_MATH_VECTOR_HPP
29 
30 #include <cstddef>
31 #include <algorithm>
32 #include <vector>
33 #include <limits>
34 #include <utility>
35 #include <unordered_map>
36 #include <type_traits>
37 #include <initializer_list>
38 #include <memory>
39 
40 #include "CDPL/Math/Check.hpp"
44 #include "CDPL/Math/Functional.hpp"
45 #include "CDPL/Math/TypeTraits.hpp"
47 #include "CDPL/Base/Exceptions.hpp"
48 
49 
50 namespace CDPL
51 {
52 
53  namespace Math
54  {
55 
56  template <typename V>
57  class VectorReference : public VectorExpression<VectorReference<V> >
58  {
59 
61 
62  public:
63  typedef V VectorType;
64  typedef typename V::ValueType ValueType;
65  typedef typename std::conditional<std::is_const<V>::value,
66  typename V::ConstReference,
67  typename V::Reference>::type Reference;
68  typedef typename V::ConstReference ConstReference;
69  typedef typename V::SizeType SizeType;
70  typedef typename V::DifferenceType DifferenceType;
72  typedef const SelfType ConstClosureType;
73 
75  data(v) {}
76 
78  {
79  return data[i];
80  }
81 
83  {
84  return data[i];
85  }
86 
88  {
89  return data(i);
90  }
91 
93  {
94  return data(i);
95  }
96 
97  SizeType getSize() const
98  {
99  return data.getSize();
100  }
101 
103  {
104  return data.getMaxSize();
105  }
106 
107  bool isEmpty() const
108  {
109  return data.isEmpty();
110  }
111 
112  const VectorType& getData() const
113  {
114  return data;
115  }
116 
118  {
119  return data;
120  }
121 
123  {
124  data.operator=(r.data);
125  return *this;
126  }
127 
128  template <typename E>
130  {
131  data.operator=(e);
132  return *this;
133  }
134 
135  template <typename E>
137  {
138  data.operator+=(e);
139  return *this;
140  }
141 
142  template <typename E>
144  {
145  data.operator-=(e);
146  return *this;
147  }
148 
149  template <typename T>
150  typename std::enable_if<IsScalar<T>::value, VectorReference>::type& operator*=(const T& t)
151  {
152  data.operator*=(t);
153  return *this;
154  }
155 
156  template <typename T>
157  typename std::enable_if<IsScalar<T>::value, VectorReference>::type& operator/=(const T& t)
158  {
159  data.operator/=(t);
160  return *this;
161  }
162 
163  template <typename E>
165  {
166  data.assign(e);
167  return *this;
168  }
169 
170  template <typename E>
172  {
173  data.plusAssign(e);
174  return *this;
175  }
176 
177  template <typename E>
179  {
180  data.minusAssign(e);
181  return *this;
182  }
183 
185  {
186  data.swap(r.data);
187  }
188 
189  friend void swap(VectorReference& r1, VectorReference& r2)
190  {
191  r1.swap(r2);
192  }
193 
194  private:
195  VectorType& data;
196  };
197 
198  template <typename T, typename A>
199  class Vector;
200 
201  template <typename T>
202  class InitListVector : public VectorContainer<InitListVector<T> >
203  {
204 
205  public:
207  typedef std::initializer_list<T> InitializerListType;
208  typedef typename InitializerListType::value_type ValueType;
209  typedef typename InitializerListType::const_reference ConstReference;
210  typedef typename InitializerListType::reference Reference;
211  typedef typename InitializerListType::size_type SizeType;
212  typedef typename std::ptrdiff_t DifferenceType;
214  typedef const SelfType ConstClosureType;
216 
218  list(l) {}
219 
221  {
222  return this->operator()(i);
223  }
224 
226  {
227  return this->operator()(i);
228  }
229 
231  {
232  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
233  return *(list.begin() + i);
234  }
235 
237  {
238  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
239  return *(list.begin() + i);
240  }
241 
243  {
244  return list.size();
245  }
246 
247  bool isEmpty() const
248  {
249  return (list.size() == 0);
250  }
251 
252  private:
253  InitializerListType list;
254  };
255 
256  template <typename T, typename A = std::vector<T> >
257  class Vector : public VectorContainer<Vector<T, A> >
258  {
259 
260  typedef Vector<T, A> SelfType;
261 
262  public:
263  typedef T ValueType;
264  typedef T& Reference;
265  typedef const T& ConstReference;
266  typedef typename A::size_type SizeType;
267  typedef typename A::difference_type DifferenceType;
268  typedef A ArrayType;
269  typedef T* Pointer;
270  typedef const T* ConstPointer;
274  typedef std::shared_ptr<SelfType> SharedPointer;
275  typedef std::initializer_list<T> InitializerListType;
276 
278  data() {}
279 
280  explicit Vector(SizeType n):
281  data(storageSize(n)) {}
282 
283  Vector(SizeType n, const ValueType& v):
284  data(storageSize(n), v) {}
285 
286  Vector(const ArrayType& data):
287  data(data) {}
288 
289  Vector(const Vector& v):
290  data(v.data) {}
291 
293  data(std::move(v.data)) {}
294 
296  data(l) {}
297 
298  template <typename E>
300  data(storageSize(e().getSize()))
301  {
302  vectorAssignVector<ScalarAssignment>(*this, e);
303  }
304 
306  {
307  return this->operator()(i);
308  }
309 
311  {
312  return this->operator()(i);
313  }
314 
316  {
317  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
318  return data[i];
319  }
320 
322  {
323  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
324  return data[i];
325  }
326 
327  bool isEmpty() const
328  {
329  return data.empty();
330  }
331 
333  {
334  return data.size();
335  }
336 
338  {
339  return data.max_size();
340  }
341 
343  {
344  return data;
345  }
346 
347  const ArrayType& getData() const
348  {
349  return data;
350  }
351 
353  {
354  data = v.data;
355  return *this;
356  }
357 
359  {
360  data = std::move(v.data);
361  return *this;
362  }
363 
365  {
366  return assign(l);
367  }
368 
369  template <typename C>
371  {
372  return assign(c);
373  }
374 
375  template <typename E>
377  {
378  Vector tmp(e);
379  swap(tmp);
380  return *this;
381  }
382 
383  template <typename C>
385  {
386  return plusAssign(c);
387  }
388 
390  {
391  return plusAssign(l);
392  }
393 
394  template <typename E>
396  {
397  Vector tmp(*this + e);
398  swap(tmp);
399  return *this;
400  }
401 
402  template <typename C>
404  {
405  return minusAssign(c);
406  }
407 
409  {
410  return minusAssign(l);
411  }
412 
413  template <typename E>
415  {
416  Vector tmp(*this - e);
417  swap(tmp);
418  return *this;
419  }
420 
421  template <typename T1>
422  typename std::enable_if<IsScalar<T1>::value, Vector>::type& operator*=(const T1& t)
423  {
424  vectorAssignScalar<ScalarMultiplicationAssignment>(*this, t);
425  return *this;
426  }
427 
428  template <typename T1>
429  typename std::enable_if<IsScalar<T1>::value, Vector>::type& operator/=(const T1& t)
430  {
431  vectorAssignScalar<ScalarDivisionAssignment>(*this, t);
432  return *this;
433  }
434 
435  template <typename E>
437  {
438  resize(e().getSize());
439  vectorAssignVector<ScalarAssignment>(*this, e);
440  return *this;
441  }
442 
444  {
445  data = l;
446  return *this;
447  }
448 
449  template <typename E>
451  {
452  vectorAssignVector<ScalarAdditionAssignment>(*this, e);
453  return *this;
454  }
455 
457  {
458  vectorAssignVector<ScalarAdditionAssignment>(*this, InitListVector<ValueType>(l));
459  return *this;
460  }
461 
462  template <typename E>
464  {
465  vectorAssignVector<ScalarSubtractionAssignment>(*this, e);
466  return *this;
467  }
468 
470  {
471  vectorAssignVector<ScalarSubtractionAssignment>(*this, InitListVector<ValueType>(l));
472  return *this;
473  }
474 
475  void swap(Vector& v)
476  {
477  if (this != &v)
478  std::swap(data, v.data);
479  }
480 
481  friend void swap(Vector& v1, Vector& v2)
482  {
483  v1.swap(v2);
484  }
485 
486  void clear(const ValueType& v = ValueType())
487  {
488  std::fill(data.begin(), data.end(), v);
489  }
490 
491  void resize(SizeType n, const ValueType& v = ValueType())
492  {
493  data.resize(storageSize(n), v);
494  }
495 
496  private:
497  SizeType storageSize(SizeType n)
498  {
499  return CDPL_MATH_CHECK_MAX_SIZE(n, data.max_size(), Base::SizeError);
500  }
501 
502  ArrayType data;
503  };
504 
505  template <typename T, typename A = std::unordered_map<std::size_t, T> >
506  class SparseVector : public VectorContainer<SparseVector<T, A> >
507  {
508 
509  typedef SparseVector<T> SelfType;
510 
511  public:
512  typedef T ValueType;
513  typedef std::size_t SizeType;
514  typedef std::ptrdiff_t DifferenceType;
515  typedef typename A::key_type KeyType;
516  typedef const T& ConstReference;
518  typedef A ArrayType;
519  typedef T* Pointer;
520  typedef const T* ConstPointer;
524  typedef std::shared_ptr<SelfType> SharedPointer;
525  typedef std::initializer_list<T> InitializerListType;
526 
528  data(), size(0) {}
529 
530  explicit SparseVector(SizeType n):
531  data(), size(storageSize(n)) {}
532 
534  data(v.data), size(v.size) {}
535 
537  data(), size(0)
538  {
539  swap(v);
540  }
541 
543  {
544  assign(l);
545  }
546 
547  template <typename E>
549  data(), size(0)
550  {
551  assign(e);
552  }
553 
555  {
556  return this->operator()(i);
557  }
558 
560  {
561  return this->operator()(i);
562  }
563 
565  {
566  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
567  return Reference(*this, i);
568  }
569 
571  {
572  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
573 
574  typename ArrayType::const_iterator it = data.find(i);
575 
576  if (it == data.end())
577  return zero;
578 
579  return it->second;
580  }
581 
583  {
584  return data.size();
585  }
586 
587  bool isEmpty() const
588  {
589  return (size == 0);
590  }
591 
593  {
594  return size;
595  }
596 
598  {
599  return std::min(SizeType(data.max_size()), std::numeric_limits<SizeType>::max());
600  }
601 
603  {
604  return data;
605  }
606 
607  const ArrayType& getData() const
608  {
609  return data;
610  }
611 
613  {
614  data = v.data;
615  size = v.size;
616  return *this;
617  }
618 
620  {
621  swap(v);
622  return *this;
623  }
624 
626  {
627  return assign(l);
628  }
629 
630  template <typename C>
632  {
633  return assign(c);
634  }
635 
636  template <typename E>
638  {
639  SparseVector tmp(e);
640  swap(tmp);
641  return *this;
642  }
643 
644  template <typename C>
646  {
647  return plusAssign(c);
648  }
649 
651  {
652  return plusAssign(l);
653  }
654 
655  template <typename E>
657  {
658  SparseVector tmp(*this + e);
659  swap(tmp);
660  return *this;
661  }
662 
663  template <typename C>
665  {
666  return minusAssign(c);
667  }
668 
670  {
671  return minusAssign(l);
672  }
673 
674  template <typename E>
676  {
677  SparseVector tmp(*this - e);
678  swap(tmp);
679  return *this;
680  }
681 
682  template <typename T1>
683  typename std::enable_if<IsScalar<T1>::value, SparseVector>::type& operator*=(const T1& t)
684  {
685  vectorAssignScalar<ScalarMultiplicationAssignment>(*this, t);
686  return *this;
687  }
688 
689  template <typename T1>
690  typename std::enable_if<IsScalar<T1>::value, SparseVector>::type& operator/=(const T1& t)
691  {
692  vectorAssignScalar<ScalarDivisionAssignment>(*this, t);
693  return *this;
694  }
695 
696  template <typename E>
698  {
699  resize(e().getSize());
700  vectorAssignVector<ScalarAssignment>(*this, e);
701  return *this;
702  }
703 
705  {
706  resize(l.size());
707  vectorAssignVector<ScalarAssignment>(*this, InitListVector<ValueType>(l));
708  return *this;
709  }
710 
711  template <typename E>
713  {
714  vectorAssignVector<ScalarAdditionAssignment>(*this, e);
715  return *this;
716  }
717 
719  {
720  vectorAssignVector<ScalarAdditionAssignment>(*this, InitListVector<ValueType>(l));
721  return *this;
722  }
723 
724  template <typename E>
726  {
727  vectorAssignVector<ScalarSubtractionAssignment>(*this, e);
728  return *this;
729  }
730 
732  {
733  vectorAssignVector<ScalarSubtractionAssignment>(*this, InitListVector<ValueType>(l));
734  return *this;
735  }
736 
738  {
739  if (this != &v) {
740  std::swap(data, v.data);
741  std::swap(size, v.size);
742  }
743  }
744 
745  friend void swap(SparseVector& v1, SparseVector& v2)
746  {
747  v1.swap(v2);
748  }
749 
750  void clear()
751  {
752  data.clear();
753  }
754 
755  void resize(SizeType n)
756  {
757  n = storageSize(n);
758 
759  for (typename ArrayType::iterator it = data.begin(); it != data.end();) {
760  if (it->first >= n)
761  it = data.erase(it);
762  else
763  ++it;
764  }
765 
766  size = n;
767  }
768 
769  private:
770  SizeType storageSize(SizeType n)
771  {
773  }
774 
775  ArrayType data;
776  SizeType size;
777  static const ValueType zero;
778  };
779 
780  template <typename T, typename A>
781  const typename SparseVector<T, A>::ValueType SparseVector<T, A>::zero = SparseVector<T, A>::ValueType();
782 
783  template <typename T, std::size_t N>
784  class BoundedVector : public VectorContainer<BoundedVector<T, N> >
785  {
786 
788 
789  public:
790  typedef T ValueType;
791  typedef T& Reference;
792  typedef const T& ConstReference;
793  typedef std::size_t SizeType;
794  typedef std::ptrdiff_t DifferenceType;
796  typedef T* Pointer;
797  typedef const T* ConstPointer;
801  typedef std::shared_ptr<SelfType> SharedPointer;
802  typedef std::initializer_list<T> InitializerListType;
803 
804  static const SizeType MaxSize = N;
805 
807  size(0) {}
808 
809  explicit BoundedVector(SizeType n):
810  size(0)
811  {
812  resize(n);
813  }
814 
816  size(0)
817  {
818  resize(n, v);
819  }
820 
822  size(v.size)
823  {
824  std::copy(v.data, v.data + v.size, data);
825  }
826 
828  {
829  assign(l);
830  }
831 
832  template <typename E>
834  size(0)
835  {
836  assign(e);
837  }
838 
840  {
841  return this->operator()(i);
842  }
843 
845  {
846  return this->operator()(i);
847  }
848 
850  {
851  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
852  return data[i];
853  }
854 
856  {
857  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
858  return data[i];
859  }
860 
861  bool isEmpty() const
862  {
863  return (size == 0);
864  }
865 
867  {
868  return size;
869  }
870 
872  {
873  return N;
874  }
875 
877  {
878  return data;
879  }
880 
882  {
883  return data;
884  }
885 
887  {
888  if (this != &v) {
889  std::copy(v.data, v.data + v.size, data);
890  size = v.size;
891  }
892 
893  return *this;
894  }
895 
897  {
898  return assign(l);
899  }
900 
901  template <typename C>
903  {
904  return assign(c);
905  }
906 
907  template <typename E>
909  {
910  BoundedVector tmp(e);
911  return this-> operator=(tmp);
912  }
913 
914  template <typename C>
916  {
917  return plusAssign(c);
918  }
919 
921  {
922  return plusAssign(l);
923  }
924 
925  template <typename E>
927  {
928  BoundedVector tmp(*this + e);
929  return this-> operator=(tmp);
930  }
931 
932  template <typename C>
934  {
935  return minusAssign(c);
936  }
937 
939  {
940  return minusAssign(l);
941  }
942 
943  template <typename E>
945  {
946  BoundedVector tmp(*this - e);
947  return this-> operator=(tmp);
948  }
949 
950  template <typename T1>
951  typename std::enable_if<IsScalar<T1>::value, BoundedVector>::type& operator*=(const T1& t)
952  {
953  vectorAssignScalar<ScalarMultiplicationAssignment>(*this, t);
954  return *this;
955  }
956 
957  template <typename T1>
958  typename std::enable_if<IsScalar<T1>::value, BoundedVector>::type& operator/=(const T1& t)
959  {
960  vectorAssignScalar<ScalarDivisionAssignment>(*this, t);
961  return *this;
962  }
963 
964  template <typename E>
966  {
967  resize(e().getSize());
968  vectorAssignVector<ScalarAssignment>(*this, e);
969  return *this;
970  }
971 
973  {
974  resize(l.size());
975  std::copy(l.begin(), l.begin() + size, data);
976  return *this;
977  }
978 
979  template <typename E>
981  {
982  vectorAssignVector<ScalarAdditionAssignment>(*this, e);
983  return *this;
984  }
985 
987  {
988  vectorAssignVector<ScalarAdditionAssignment>(*this, InitListVector<ValueType>(l));
989  return *this;
990  }
991 
992  template <typename E>
994  {
995  vectorAssignVector<ScalarSubtractionAssignment>(*this, e);
996  return *this;
997  }
998 
1000  {
1001  vectorAssignVector<ScalarSubtractionAssignment>(*this, InitListVector<ValueType>(l));
1002  return *this;
1003  }
1004 
1006  {
1007  if (this != &v) {
1008  std::swap_ranges(data, data + std::max(size, v.size), v.data);
1009  std::swap(size, v.size);
1010  }
1011  }
1012 
1013  friend void swap(BoundedVector& v1, BoundedVector& v2)
1014  {
1015  v1.swap(v2);
1016  }
1017 
1018  void clear(const ValueType& v = ValueType())
1019  {
1020  std::fill(data, data + size, v);
1021  }
1022 
1024  {
1025  size = storageSize(n);
1026  }
1027 
1028  void resize(SizeType n, const ValueType& v)
1029  {
1030  n = storageSize(n);
1031 
1032  if (n > size)
1033  std::fill(data + size, data + n, v);
1034 
1035  size = n;
1036  }
1037 
1038  private:
1039  SizeType storageSize(SizeType n)
1040  {
1042  }
1043 
1044  ArrayType data;
1045  SizeType size;
1046  };
1047 
1048  template <typename T, std::size_t N>
1050 
1051  template <typename T, std::size_t N>
1052  class CVector : public VectorContainer<CVector<T, N> >
1053  {
1054 
1055  typedef CVector<T, N> SelfType;
1056 
1057  public:
1058  typedef T ValueType;
1059  typedef T& Reference;
1060  typedef const T& ConstReference;
1061  typedef std::size_t SizeType;
1062  typedef std::ptrdiff_t DifferenceType;
1064  typedef T* Pointer;
1065  typedef const T* ConstPointer;
1069  typedef std::shared_ptr<SelfType> SharedPointer;
1070  typedef std::initializer_list<T> InitializerListType;
1071 
1072  static const SizeType Size = N;
1073 
1075  {
1076  clear();
1077  }
1078 
1079  explicit CVector(const ValueType& v)
1080  {
1081  clear(v);
1082  }
1083 
1084  CVector(const CVector& v)
1085  {
1086  std::copy(v.data, v.data + N, data);
1087  }
1088 
1090  {
1091  assign(l);
1092  }
1093 
1094  template <typename E>
1096  {
1097  vectorAssignVector<ScalarAssignment>(*this, e);
1098  }
1099 
1101  {
1102  return this->operator()(i);
1103  }
1104 
1106  {
1107  return this->operator()(i);
1108  }
1109 
1111  {
1112  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
1113  return data[i];
1114  }
1115 
1117  {
1118  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
1119  return data[i];
1120  }
1121 
1122  bool isEmpty() const
1123  {
1124  return (N == 0);
1125  }
1126 
1128  {
1129  return N;
1130  }
1131 
1133  {
1134  return N;
1135  }
1136 
1138  {
1139  return data;
1140  }
1141 
1143  {
1144  return data;
1145  }
1146 
1148  {
1149  if (this != &v)
1150  std::copy(v.data, v.data + N, data);
1151 
1152  return *this;
1153  }
1154 
1156  {
1157  return assign(l);
1158  }
1159 
1160  template <typename C>
1162  {
1163  return assign(c);
1164  }
1165 
1166  template <typename E>
1168  {
1169  CVector tmp(e);
1170  return this->operator=(tmp);
1171  }
1172 
1173  template <typename C>
1175  {
1176  return plusAssign(c);
1177  }
1178 
1180  {
1181  return plusAssign(l);
1182  }
1183 
1184  template <typename E>
1186  {
1187  CVector tmp(*this + e);
1188  return this->operator=(tmp);
1189  }
1190 
1191  template <typename C>
1193  {
1194  return minusAssign(c);
1195  }
1196 
1198  {
1199  return minusAssign(l);
1200  }
1201 
1202  template <typename E>
1204  {
1205  CVector tmp(*this - e);
1206  return this->operator=(tmp);
1207  }
1208 
1209  template <typename T1>
1210  typename std::enable_if<IsScalar<T1>::value, CVector>::type& operator*=(const T1& t)
1211  {
1212  vectorAssignScalar<ScalarMultiplicationAssignment>(*this, t);
1213  return *this;
1214  }
1215 
1216  template <typename T1>
1217  typename std::enable_if<IsScalar<T1>::value, CVector>::type& operator/=(const T1& t)
1218  {
1219  vectorAssignScalar<ScalarDivisionAssignment>(*this, t);
1220  return *this;
1221  }
1222 
1223  template <typename E>
1225  {
1226  vectorAssignVector<ScalarAssignment>(*this, e);
1227  return *this;
1228  }
1229 
1231  {
1233  std::copy(l.begin(), l.begin() + n, data);
1234 
1235  if (n < N)
1236  std::fill(data + n, data + N, ValueType());
1237 
1238  return *this;
1239  }
1240 
1241  template <typename E>
1243  {
1244  vectorAssignVector<ScalarAdditionAssignment>(*this, e);
1245  return *this;
1246  }
1247 
1249  {
1250  vectorAssignVector<ScalarAdditionAssignment>(*this, InitListVector<ValueType>(l));
1251  return *this;
1252  }
1253 
1254  template <typename E>
1256  {
1257  vectorAssignVector<ScalarSubtractionAssignment>(*this, e);
1258  return *this;
1259  }
1260 
1262  {
1263  vectorAssignVector<ScalarSubtractionAssignment>(*this, InitListVector<ValueType>(l));
1264  return *this;
1265  }
1266 
1267  void swap(CVector& v)
1268  {
1269  if (this != &v)
1270  std::swap_ranges(data, data + N, v.data);
1271  }
1272 
1273  friend void swap(CVector& v1, CVector& v2)
1274  {
1275  v1.swap(v2);
1276  }
1277 
1278  void clear(const ValueType& v = ValueType())
1279  {
1280  std::fill(data, data + N, v);
1281  }
1282 
1283  private:
1284  ArrayType data;
1285  };
1286 
1287  template <typename T, std::size_t N>
1289 
1290  template <typename T>
1291  class ZeroVector : public VectorContainer<ZeroVector<T> >
1292  {
1293 
1294  typedef ZeroVector<T> SelfType;
1295 
1296  public:
1297  typedef T ValueType;
1298  typedef const T& Reference;
1299  typedef const T& ConstReference;
1300  typedef std::size_t SizeType;
1301  typedef std::ptrdiff_t DifferenceType;
1305 
1307  size(0) {}
1308 
1309  explicit ZeroVector(SizeType n):
1310  size(n) {}
1311 
1313  size(v.size) {}
1314 
1316  {
1317  return this->operator()(i);
1318  }
1319 
1321  {
1322  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
1323  return zero;
1324  }
1325 
1326  bool isEmpty() const
1327  {
1328  return (size == 0);
1329  }
1330 
1332  {
1333  return size;
1334  }
1335 
1337  {
1338  return std::numeric_limits<SizeType>::max();
1339  }
1340 
1342  {
1343  size = v.size;
1344  return *this;
1345  }
1346 
1348  {
1349  size = n;
1350  }
1351 
1352  void swap(ZeroVector& v)
1353  {
1354  if (this != &v)
1355  std::swap(size, v.size);
1356  }
1357 
1358  friend void swap(ZeroVector& v1, ZeroVector& v2)
1359  {
1360  v1.swap(v2);
1361  }
1362 
1363  private:
1364  SizeType size;
1365  static const ValueType zero;
1366  };
1367 
1368  template <typename T>
1369  const typename ZeroVector<T>::ValueType ZeroVector<T>::zero = ZeroVector<T>::ValueType();
1370 
1371  template <typename T>
1372  class UnitVector : public VectorContainer<UnitVector<T> >
1373  {
1374 
1375  typedef UnitVector<T> SelfType;
1376 
1377  public:
1378  typedef T ValueType;
1379  typedef const T& Reference;
1380  typedef const T& ConstReference;
1381  typedef std::size_t SizeType;
1382  typedef std::ptrdiff_t DifferenceType;
1386 
1388  size(0), index(0) {}
1389 
1391  size(n), index(i) {}
1392 
1394  size(v.size), index(v.index) {}
1395 
1397  {
1398  return this->operator()(i);
1399  }
1400 
1402  {
1403  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
1404 
1405  return (i == index ? one : zero);
1406  }
1407 
1408  bool isEmpty() const
1409  {
1410  return (size == 0);
1411  }
1412 
1414  {
1415  return size;
1416  }
1417 
1419  {
1420  return index;
1421  }
1422 
1424  {
1425  return std::numeric_limits<SizeType>::max();
1426  }
1427 
1429  {
1430  if (this != &v) {
1431  size = v.size;
1432  index = v.index;
1433  }
1434 
1435  return *this;
1436  }
1437 
1439  {
1440  size = n;
1441  }
1442 
1443  void swap(UnitVector& v)
1444  {
1445  if (this != &v) {
1446  std::swap(size, v.size);
1447  std::swap(index, v.index);
1448  }
1449  }
1450 
1451  friend void swap(UnitVector& v1, UnitVector& v2)
1452  {
1453  v1.swap(v2);
1454  }
1455 
1456  private:
1457  SizeType size;
1458  SizeType index;
1459  static const ValueType zero;
1460  static const ValueType one;
1461  };
1462 
1463  template <typename T>
1464  const typename UnitVector<T>::ValueType UnitVector<T>::zero = UnitVector<T>::ValueType();
1465  template <typename T>
1466  const typename UnitVector<T>::ValueType UnitVector<T>::one = UnitVector<T>::ValueType(1);
1467 
1468  template <typename T>
1469  class ScalarVector : public VectorContainer<ScalarVector<T> >
1470  {
1471 
1472  typedef ScalarVector<T> SelfType;
1473 
1474  public:
1475  typedef T ValueType;
1476  typedef const T& Reference;
1477  typedef const T& ConstReference;
1478  typedef std::size_t SizeType;
1479  typedef std::ptrdiff_t DifferenceType;
1483 
1485  size(0) {}
1486 
1488  size(n), value(v) {}
1489 
1491  size(v.size), value(v.value) {}
1492 
1494  {
1495  return this->operator()(i);
1496  }
1497 
1499  {
1500  CDPL_MATH_CHECK(i < getSize(), "Index out of range", Base::IndexError);
1501  return value;
1502  }
1503 
1504  bool isEmpty() const
1505  {
1506  return (size == 0);
1507  }
1508 
1510  {
1511  return size;
1512  }
1513 
1515  {
1516  return std::numeric_limits<SizeType>::max();
1517  }
1518 
1520  {
1521  if (this != &v) {
1522  size = v.size;
1523  value = v.value;
1524  }
1525 
1526  return *this;
1527  }
1528 
1530  {
1531  size = n;
1532  }
1533 
1535  {
1536  if (this != &v) {
1537  std::swap(size, v.size);
1538  std::swap(value, v.value);
1539  }
1540  }
1541 
1542  friend void swap(ScalarVector& v1, ScalarVector& v2)
1543  {
1544  v1.swap(v2);
1545  }
1546 
1547  private:
1548  SizeType size;
1549  ValueType value;
1550  };
1551 
1552  template <typename V>
1554  {};
1555 
1556  template <typename V>
1558  {};
1559 
1560  template <typename T1, typename T2>
1562  vec(const T1& t1, const T2& t2)
1563  {
1565 
1566  v(0) = t1;
1567  v(1) = t2;
1568 
1569  return v;
1570  }
1571 
1572  template <typename T1, typename T2, typename T3>
1573  CVector<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type, 3>
1574  vec(const T1& t1, const T2& t2, const T3& t3)
1575  {
1577 
1578  v(0) = t1;
1579  v(1) = t2;
1580  v(2) = t3;
1581 
1582  return v;
1583  }
1584 
1585  template <typename T1, typename T2, typename T3, typename T4>
1586  CVector<typename CommonType<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type, T4>::Type, 4>
1587  vec(const T1& t1, const T2& t2, const T3& t3, const T4& t4)
1588  {
1590 
1591  v(0) = t1;
1592  v(1) = t2;
1593  v(2) = t3;
1594  v(3) = t4;
1595 
1596  return v;
1597  }
1598 
1603 
1608 
1613 
1618 
1623 
1628 
1633 
1638 
1643 
1648 
1653 
1658 
1663 
1668 
1673 
1678 
1683 
1688 
1693 
1698 
1703 
1708 
1713 
1718  } // namespace Math
1719 } // namespace CDPL
1720 
1721 #endif // CDPL_MATH_VECTOR_HPP
Definition of exception classes.
Definition of various preprocessor macros for error checking.
#define CDPL_MATH_CHECK_MAX_SIZE(size, max_size, e)
Definition: Check.hpp:64
#define CDPL_MATH_CHECK(expr, msg, e)
Definition: Check.hpp:36
Definition of a proxy type for direct assignment of vector and matrix expressions.
Definition of various functors.
Definition of an element proxy for sparse data types.
Definition of type traits.
Implementation of vector assignment routines.
Definition of various vector expression types and operations.
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
Definition: Vector.hpp:785
static const SizeType MaxSize
Definition: Vector.hpp:804
std::shared_ptr< SelfType > SharedPointer
Definition: Vector.hpp:801
BoundedVector & operator=(const BoundedVector &v)
Definition: Vector.hpp:886
BoundedVector & operator+=(const VectorContainer< C > &c)
Definition: Vector.hpp:915
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:844
T & Reference
Definition: Vector.hpp:791
void resize(SizeType n, const ValueType &v)
Definition: Vector.hpp:1028
void swap(BoundedVector &v)
Definition: Vector.hpp:1005
BoundedVector & operator+=(const VectorExpression< E > &e)
Definition: Vector.hpp:926
void clear(const ValueType &v=ValueType())
Definition: Vector.hpp:1018
Pointer getData()
Definition: Vector.hpp:876
BoundedVector(const VectorExpression< E > &e)
Definition: Vector.hpp:833
BoundedVector & assign(InitializerListType l)
Definition: Vector.hpp:972
Reference operator()(SizeType i)
Definition: Vector.hpp:849
std::enable_if< IsScalar< T1 >::value, BoundedVector >::type & operator*=(const T1 &t)
Definition: Vector.hpp:951
void resize(SizeType n)
Definition: Vector.hpp:1023
BoundedVector & assign(const VectorExpression< E > &e)
Definition: Vector.hpp:965
std::initializer_list< T > InitializerListType
Definition: Vector.hpp:802
BoundedVector & minusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:993
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:855
ConstPointer getData() const
Definition: Vector.hpp:881
SizeType getMaxSize() const
Definition: Vector.hpp:871
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:799
BoundedVector(InitializerListType l)
Definition: Vector.hpp:827
BoundedVector & operator=(const VectorContainer< C > &c)
Definition: Vector.hpp:902
BoundedVector & plusAssign(InitializerListType l)
Definition: Vector.hpp:986
const T * ConstPointer
Definition: Vector.hpp:797
Reference operator[](SizeType i)
Definition: Vector.hpp:839
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:794
BoundedVector()
Definition: Vector.hpp:806
BoundedVector & plusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:980
SizeType getSize() const
Definition: Vector.hpp:866
BoundedVector(SizeType n)
Definition: Vector.hpp:809
BoundedVector & minusAssign(InitializerListType l)
Definition: Vector.hpp:999
BoundedVector & operator-=(InitializerListType l)
Definition: Vector.hpp:938
T ValueType
Definition: Vector.hpp:790
bool isEmpty() const
Definition: Vector.hpp:861
ValueType ArrayType[N]
Definition: Vector.hpp:795
BoundedVector & operator=(InitializerListType l)
Definition: Vector.hpp:896
T * Pointer
Definition: Vector.hpp:796
std::size_t SizeType
Definition: Vector.hpp:793
BoundedVector & operator-=(const VectorExpression< E > &e)
Definition: Vector.hpp:944
BoundedVector & operator-=(const VectorContainer< C > &c)
Definition: Vector.hpp:933
BoundedVector(SizeType n, const ValueType &v)
Definition: Vector.hpp:815
friend void swap(BoundedVector &v1, BoundedVector &v2)
Definition: Vector.hpp:1013
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:798
const T & ConstReference
Definition: Vector.hpp:792
BoundedVector< T, N+1 > VectorTemporaryType
Definition: Vector.hpp:800
BoundedVector & operator=(const VectorExpression< E > &e)
Definition: Vector.hpp:908
BoundedVector(const BoundedVector &v)
Definition: Vector.hpp:821
std::enable_if< IsScalar< T1 >::value, BoundedVector >::type & operator/=(const T1 &t)
Definition: Vector.hpp:958
BoundedVector & operator+=(InitializerListType l)
Definition: Vector.hpp:920
Definition: Vector.hpp:1053
std::enable_if< IsScalar< T1 >::value, CVector >::type & operator/=(const T1 &t)
Definition: Vector.hpp:1217
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:1116
std::size_t SizeType
Definition: Vector.hpp:1061
CVector & operator=(const VectorExpression< E > &e)
Definition: Vector.hpp:1167
Pointer getData()
Definition: Vector.hpp:1137
static const SizeType Size
Definition: Vector.hpp:1072
T ValueType
Definition: Vector.hpp:1058
void clear(const ValueType &v=ValueType())
Definition: Vector.hpp:1278
SizeType getMaxSize() const
Definition: Vector.hpp:1132
CVector & operator=(InitializerListType l)
Definition: Vector.hpp:1155
const T & ConstReference
Definition: Vector.hpp:1060
ConstPointer getData() const
Definition: Vector.hpp:1142
ValueType ArrayType[N]
Definition: Vector.hpp:1063
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:1105
bool isEmpty() const
Definition: Vector.hpp:1122
Reference operator()(SizeType i)
Definition: Vector.hpp:1110
CVector & plusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:1242
CVector & operator-=(InitializerListType l)
Definition: Vector.hpp:1197
CVector & plusAssign(InitializerListType l)
Definition: Vector.hpp:1248
CVector & operator+=(const VectorExpression< E > &e)
Definition: Vector.hpp:1185
SizeType getSize() const
Definition: Vector.hpp:1127
CVector & operator=(const VectorContainer< C > &c)
Definition: Vector.hpp:1161
T * Pointer
Definition: Vector.hpp:1064
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:1066
CVector & operator+=(InitializerListType l)
Definition: Vector.hpp:1179
CVector(InitializerListType l)
Definition: Vector.hpp:1089
void swap(CVector &v)
Definition: Vector.hpp:1267
BoundedVector< T, N+1 > VectorTemporaryType
Definition: Vector.hpp:1068
CVector & assign(const VectorExpression< E > &e)
Definition: Vector.hpp:1224
Reference operator[](SizeType i)
Definition: Vector.hpp:1100
const T * ConstPointer
Definition: Vector.hpp:1065
std::shared_ptr< SelfType > SharedPointer
Definition: Vector.hpp:1069
CVector & operator-=(const VectorExpression< E > &e)
Definition: Vector.hpp:1203
CVector & minusAssign(InitializerListType l)
Definition: Vector.hpp:1261
CVector & operator+=(const VectorContainer< C > &c)
Definition: Vector.hpp:1174
T & Reference
Definition: Vector.hpp:1059
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:1067
CVector & minusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:1255
CVector & operator=(const CVector &v)
Definition: Vector.hpp:1147
CVector(const ValueType &v)
Definition: Vector.hpp:1079
std::initializer_list< T > InitializerListType
Definition: Vector.hpp:1070
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:1062
CVector & assign(InitializerListType l)
Definition: Vector.hpp:1230
CVector()
Definition: Vector.hpp:1074
CVector(const VectorExpression< E > &e)
Definition: Vector.hpp:1095
CVector & operator-=(const VectorContainer< C > &c)
Definition: Vector.hpp:1192
CVector(const CVector &v)
Definition: Vector.hpp:1084
friend void swap(CVector &v1, CVector &v2)
Definition: Vector.hpp:1273
std::enable_if< IsScalar< T1 >::value, CVector >::type & operator*=(const T1 &t)
Definition: Vector.hpp:1210
Definition: Vector.hpp:203
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:236
InitializerListType::const_reference ConstReference
Definition: Vector.hpp:209
const SelfType ConstClosureType
Definition: Vector.hpp:214
Reference operator[](SizeType i)
Definition: Vector.hpp:220
Reference operator()(SizeType i)
Definition: Vector.hpp:230
std::initializer_list< T > InitializerListType
Definition: Vector.hpp:207
SizeType getSize() const
Definition: Vector.hpp:242
InitListVector(InitializerListType l)
Definition: Vector.hpp:217
bool isEmpty() const
Definition: Vector.hpp:247
InitializerListType::value_type ValueType
Definition: Vector.hpp:208
InitializerListType::reference Reference
Definition: Vector.hpp:210
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:212
InitializerListType::size_type SizeType
Definition: Vector.hpp:211
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:225
SelfType ClosureType
Definition: Vector.hpp:213
Vector< T, std::vector< T > > VectorTemporaryType
Definition: Vector.hpp:215
InitListVector SelfType
Definition: Vector.hpp:206
Definition: Vector.hpp:1470
std::size_t SizeType
Definition: Vector.hpp:1478
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:1498
SizeType getMaxSize() const
Definition: Vector.hpp:1514
const T & ConstReference
Definition: Vector.hpp:1477
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:1493
const T & Reference
Definition: Vector.hpp:1476
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:1480
ScalarVector()
Definition: Vector.hpp:1484
friend void swap(ScalarVector &v1, ScalarVector &v2)
Definition: Vector.hpp:1542
ScalarVector & operator=(const ScalarVector &v)
Definition: Vector.hpp:1519
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:1481
Vector< T > VectorTemporaryType
Definition: Vector.hpp:1482
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:1479
T ValueType
Definition: Vector.hpp:1475
SizeType getSize() const
Definition: Vector.hpp:1509
void resize(SizeType n)
Definition: Vector.hpp:1529
void swap(ScalarVector &v)
Definition: Vector.hpp:1534
bool isEmpty() const
Definition: Vector.hpp:1504
ScalarVector(SizeType n, const ValueType &v=ValueType())
Definition: Vector.hpp:1487
ScalarVector(const ScalarVector &v)
Definition: Vector.hpp:1490
Definition: SparseContainerElement.hpp:42
Definition: Vector.hpp:507
SparseVector & operator=(InitializerListType l)
Definition: Vector.hpp:625
SparseVector & operator=(SparseVector &&v)
Definition: Vector.hpp:619
SparseVector & operator-=(const VectorExpression< E > &e)
Definition: Vector.hpp:675
SparseVector & operator+=(InitializerListType l)
Definition: Vector.hpp:650
SparseVector & operator=(const VectorExpression< E > &e)
Definition: Vector.hpp:637
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:570
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:522
SparseVector(const VectorExpression< E > &e)
Definition: Vector.hpp:548
SizeType getMaxSize() const
Definition: Vector.hpp:597
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:514
SparseVector & operator+=(const VectorContainer< C > &c)
Definition: Vector.hpp:645
void resize(SizeType n)
Definition: Vector.hpp:755
SparseVector(SparseVector &&v)
Definition: Vector.hpp:536
SizeType getSize() const
Definition: Vector.hpp:592
A::key_type KeyType
Definition: Vector.hpp:515
std::initializer_list< T > InitializerListType
Definition: Vector.hpp:525
SparseVector(const SparseVector &v)
Definition: Vector.hpp:533
void swap(SparseVector &v)
Definition: Vector.hpp:737
SizeType getNumElements() const
Definition: Vector.hpp:582
T * Pointer
Definition: Vector.hpp:519
SparseVector(SizeType n)
Definition: Vector.hpp:530
SparseVector & operator-=(const VectorContainer< C > &c)
Definition: Vector.hpp:664
SparseVector(InitializerListType l)
Definition: Vector.hpp:542
SparseVector()
Definition: Vector.hpp:527
std::shared_ptr< SelfType > SharedPointer
Definition: Vector.hpp:524
A ArrayType
Definition: Vector.hpp:518
SparseVector & operator=(const VectorContainer< C > &c)
Definition: Vector.hpp:631
SparseVector & minusAssign(InitializerListType l)
Definition: Vector.hpp:731
SparseContainerElement< SelfType, KeyType > Reference
Definition: Vector.hpp:517
ArrayType & getData()
Definition: Vector.hpp:602
SparseVector & operator-=(InitializerListType l)
Definition: Vector.hpp:669
SparseVector & assign(const VectorExpression< E > &e)
Definition: Vector.hpp:697
const T * ConstPointer
Definition: Vector.hpp:520
std::enable_if< IsScalar< T1 >::value, SparseVector >::type & operator*=(const T1 &t)
Definition: Vector.hpp:683
Reference operator()(SizeType i)
Definition: Vector.hpp:564
const ArrayType & getData() const
Definition: Vector.hpp:607
SparseVector & assign(InitializerListType l)
Definition: Vector.hpp:704
SelfType VectorTemporaryType
Definition: Vector.hpp:523
Reference operator[](SizeType i)
Definition: Vector.hpp:554
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:559
bool isEmpty() const
Definition: Vector.hpp:587
void clear()
Definition: Vector.hpp:750
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:521
SparseVector & plusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:712
std::enable_if< IsScalar< T1 >::value, SparseVector >::type & operator/=(const T1 &t)
Definition: Vector.hpp:690
SparseVector & plusAssign(InitializerListType l)
Definition: Vector.hpp:718
std::size_t SizeType
Definition: Vector.hpp:513
const T & ConstReference
Definition: Vector.hpp:516
T ValueType
Definition: Vector.hpp:512
friend void swap(SparseVector &v1, SparseVector &v2)
Definition: Vector.hpp:745
SparseVector & operator+=(const VectorExpression< E > &e)
Definition: Vector.hpp:656
SparseVector & operator=(const SparseVector &v)
Definition: Vector.hpp:612
SparseVector & minusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:725
Definition: Vector.hpp:1373
T ValueType
Definition: Vector.hpp:1378
void swap(UnitVector &v)
Definition: Vector.hpp:1443
const T & Reference
Definition: Vector.hpp:1379
std::size_t SizeType
Definition: Vector.hpp:1381
UnitVector & operator=(const UnitVector &v)
Definition: Vector.hpp:1428
friend void swap(UnitVector &v1, UnitVector &v2)
Definition: Vector.hpp:1451
const T & ConstReference
Definition: Vector.hpp:1380
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:1401
void resize(SizeType n)
Definition: Vector.hpp:1438
SizeType getSize() const
Definition: Vector.hpp:1413
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:1384
Vector< T > VectorTemporaryType
Definition: Vector.hpp:1385
UnitVector()
Definition: Vector.hpp:1387
UnitVector(SizeType n, SizeType i)
Definition: Vector.hpp:1390
bool isEmpty() const
Definition: Vector.hpp:1408
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:1382
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:1396
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:1383
UnitVector(const UnitVector &v)
Definition: Vector.hpp:1393
SizeType getMaxSize() const
Definition: Vector.hpp:1423
SizeType getIndex() const
Definition: Vector.hpp:1418
Definition: Expression.hpp:142
const ContainerType & operator()() const
Definition: Expression.hpp:147
Definition: Expression.hpp:54
Definition: Vector.hpp:58
SizeType getMaxSize() const
Definition: Vector.hpp:102
V::DifferenceType DifferenceType
Definition: Vector.hpp:70
V::ConstReference ConstReference
Definition: Vector.hpp:68
V VectorType
Definition: Vector.hpp:63
VectorReference & assign(const VectorExpression< E > &e)
Definition: Vector.hpp:164
VectorReference & operator=(const VectorReference &r)
Definition: Vector.hpp:122
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:82
VectorReference & operator=(const VectorExpression< E > &e)
Definition: Vector.hpp:129
VectorReference & operator+=(const VectorExpression< E > &e)
Definition: Vector.hpp:136
V::ValueType ValueType
Definition: Vector.hpp:64
const VectorType & getData() const
Definition: Vector.hpp:112
SizeType getSize() const
Definition: Vector.hpp:97
VectorReference & minusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:178
V::SizeType SizeType
Definition: Vector.hpp:69
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:92
std::enable_if< IsScalar< T >::value, VectorReference >::type & operator*=(const T &t)
Definition: Vector.hpp:150
VectorType & getData()
Definition: Vector.hpp:117
SelfType ClosureType
Definition: Vector.hpp:71
std::conditional< std::is_const< V >::value, typename V::ConstReference, typename V::Reference >::type Reference
Definition: Vector.hpp:67
std::enable_if< IsScalar< T >::value, VectorReference >::type & operator/=(const T &t)
Definition: Vector.hpp:157
Reference operator[](SizeType i)
Definition: Vector.hpp:77
Reference operator()(SizeType i)
Definition: Vector.hpp:87
friend void swap(VectorReference &r1, VectorReference &r2)
Definition: Vector.hpp:189
VectorReference & operator-=(const VectorExpression< E > &e)
Definition: Vector.hpp:143
bool isEmpty() const
Definition: Vector.hpp:107
VectorReference(VectorType &v)
Definition: Vector.hpp:74
VectorReference & plusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:171
void swap(VectorReference &r)
Definition: Vector.hpp:184
const SelfType ConstClosureType
Definition: Vector.hpp:72
Definition: Vector.hpp:258
Vector & minusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:463
Vector & minusAssign(InitializerListType l)
Definition: Vector.hpp:469
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:310
void clear(const ValueType &v=ValueType())
Definition: Vector.hpp:486
Vector & plusAssign(InitializerListType l)
Definition: Vector.hpp:456
Vector(Vector &&v)
Definition: Vector.hpp:292
Vector & operator-=(InitializerListType l)
Definition: Vector.hpp:408
Vector(InitializerListType l)
Definition: Vector.hpp:295
Vector & operator=(const Vector &v)
Definition: Vector.hpp:352
ArrayType & getData()
Definition: Vector.hpp:342
Vector & operator=(Vector &&v)
Definition: Vector.hpp:358
Vector(const ArrayType &data)
Definition: Vector.hpp:286
Reference operator[](SizeType i)
Definition: Vector.hpp:305
const T * ConstPointer
Definition: Vector.hpp:270
std::enable_if< IsScalar< T1 >::value, Vector >::type & operator*=(const T1 &t)
Definition: Vector.hpp:422
SizeType getSize() const
Definition: Vector.hpp:332
const ArrayType & getData() const
Definition: Vector.hpp:347
Vector(SizeType n)
Definition: Vector.hpp:280
std::enable_if< IsScalar< T1 >::value, Vector >::type & operator/=(const T1 &t)
Definition: Vector.hpp:429
Vector & operator=(InitializerListType l)
Definition: Vector.hpp:364
A::size_type SizeType
Definition: Vector.hpp:266
T ValueType
Definition: Vector.hpp:263
Reference operator()(SizeType i)
Definition: Vector.hpp:315
SelfType VectorTemporaryType
Definition: Vector.hpp:273
Vector & assign(const VectorExpression< E > &e)
Definition: Vector.hpp:436
Vector(const VectorExpression< E > &e)
Definition: Vector.hpp:299
Vector & operator+=(InitializerListType l)
Definition: Vector.hpp:389
Vector & operator-=(const VectorExpression< E > &e)
Definition: Vector.hpp:414
T & Reference
Definition: Vector.hpp:264
void swap(Vector &v)
Definition: Vector.hpp:475
Vector & operator+=(const VectorContainer< C > &c)
Definition: Vector.hpp:384
Vector & operator=(const VectorContainer< C > &c)
Definition: Vector.hpp:370
Vector & operator=(const VectorExpression< E > &e)
Definition: Vector.hpp:376
Vector(SizeType n, const ValueType &v)
Definition: Vector.hpp:283
bool isEmpty() const
Definition: Vector.hpp:327
Vector & assign(InitializerListType l)
Definition: Vector.hpp:443
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:321
Vector(const Vector &v)
Definition: Vector.hpp:289
std::initializer_list< T > InitializerListType
Definition: Vector.hpp:275
Vector & plusAssign(const VectorExpression< E > &e)
Definition: Vector.hpp:450
friend void swap(Vector &v1, Vector &v2)
Definition: Vector.hpp:481
Vector & operator-=(const VectorContainer< C > &c)
Definition: Vector.hpp:403
std::shared_ptr< SelfType > SharedPointer
Definition: Vector.hpp:274
Vector & operator+=(const VectorExpression< E > &e)
Definition: Vector.hpp:395
A::difference_type DifferenceType
Definition: Vector.hpp:267
const T & ConstReference
Definition: Vector.hpp:265
A ArrayType
Definition: Vector.hpp:268
T * Pointer
Definition: Vector.hpp:269
void resize(SizeType n, const ValueType &v=ValueType())
Definition: Vector.hpp:491
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:272
SizeType getMaxSize() const
Definition: Vector.hpp:337
Vector()
Definition: Vector.hpp:277
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:271
Definition: Vector.hpp:1292
std::size_t SizeType
Definition: Vector.hpp:1300
std::ptrdiff_t DifferenceType
Definition: Vector.hpp:1301
ZeroVector(SizeType n)
Definition: Vector.hpp:1309
Vector< T > VectorTemporaryType
Definition: Vector.hpp:1304
const T & ConstReference
Definition: Vector.hpp:1299
bool isEmpty() const
Definition: Vector.hpp:1326
const T & Reference
Definition: Vector.hpp:1298
ZeroVector(const ZeroVector &v)
Definition: Vector.hpp:1312
ZeroVector & operator=(const ZeroVector &v)
Definition: Vector.hpp:1341
ZeroVector()
Definition: Vector.hpp:1306
friend void swap(ZeroVector &v1, ZeroVector &v2)
Definition: Vector.hpp:1358
const VectorReference< const SelfType > ConstClosureType
Definition: Vector.hpp:1303
T ValueType
Definition: Vector.hpp:1297
ConstReference operator()(SizeType i) const
Definition: Vector.hpp:1320
SizeType getMaxSize() const
Definition: Vector.hpp:1336
ConstReference operator[](SizeType i) const
Definition: Vector.hpp:1315
VectorReference< SelfType > ClosureType
Definition: Vector.hpp:1302
void swap(ZeroVector &v)
Definition: Vector.hpp:1352
SizeType getSize() const
Definition: Vector.hpp:1331
void resize(SizeType n)
Definition: Vector.hpp:1347
constexpr unsigned int A
A generic type that covers any element except hydrogen.
Definition: AtomType.hpp:637
constexpr unsigned int N
Specifies Nitrogen.
Definition: AtomType.hpp:97
constexpr unsigned int V
Specifies Vanadium.
Definition: AtomType.hpp:177
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int r
Specifies that the stereocenter has r configuration.
Definition: CIPDescriptor.hpp:76
CVector< unsigned long, 4 > Vector4UL
A bounded 4 element vector holding unsigned integers of type unsigned long.
Definition: Vector.hpp:1677
CVector< float, 2 > Vector2F
A bounded 2 element vector holding floating point values of type float.
Definition: Vector.hpp:1617
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
SparseVector< unsigned long > SparseULVector
An unbounded sparse vector holding unsigned integers of type unsigned long.
Definition: Vector.hpp:1717
CVector< double, 7 > Vector7D
A bounded 7 element vector holding floating point values of type double.
Definition: Vector.hpp:1647
SparseVector< float > SparseFVector
An unbounded sparse vector holding floating point values of type float.
Definition: Vector.hpp:1702
UnitVector< unsigned long > ULUnitVector
Definition: Vector.hpp:1612
UnitVector< float > FUnitVector
Definition: Vector.hpp:1609
CVector< double, 4 > Vector4D
A bounded 4 element vector holding floating point values of type double.
Definition: Vector.hpp:1642
SparseVector< long > SparseLVector
An unbounded sparse vector holding signed integers of type long.
Definition: Vector.hpp:1712
ScalarVector< double > DScalarVector
Definition: Vector.hpp:1600
CVector< float, 4 > Vector4F
A bounded 4 element vector holding floating point values of type float.
Definition: Vector.hpp:1627
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
Vector< float > FVector
An unbounded dense vector holding floating point values of type float.
Definition: Vector.hpp:1682
Vector< double > DVector
An unbounded dense vector holding floating point values of type double.
Definition: Vector.hpp:1687
CVector< double, 3 > Vector3D
A bounded 3 element vector holding floating point values of type double.
Definition: Vector.hpp:1637
UnitVector< double > DUnitVector
Definition: Vector.hpp:1610
UnitVector< long > LUnitVector
Definition: Vector.hpp:1611
ZeroVector< long > LZeroVector
Definition: Vector.hpp:1606
ScalarVector< long > LScalarVector
Definition: Vector.hpp:1601
ScalarVector< unsigned long > ULScalarVector
Definition: Vector.hpp:1602
ZeroVector< unsigned long > ULZeroVector
Definition: Vector.hpp:1607
CVector< float, 3 > Vector3F
A bounded 3 element vector holding floating point values of type float.
Definition: Vector.hpp:1622
Vector< unsigned long > ULVector
An unbounded dense vector holding unsigned integers of type unsigned long.
Definition: Vector.hpp:1697
CVector< long, 4 > Vector4L
A bounded 4 element vector holding signed integers of type long.
Definition: Vector.hpp:1662
ZeroVector< double > DZeroVector
Definition: Vector.hpp:1605
CVector< unsigned long, 2 > Vector2UL
A bounded 2 element vector holding unsigned integers of type unsigned long.
Definition: Vector.hpp:1667
CVector< long, 3 > Vector3L
A bounded 3 element vector holding signed integers of type long.
Definition: Vector.hpp:1657
CVector< long, 2 > Vector2L
A bounded 2 element vector holding signed integers of type long.
Definition: Vector.hpp:1652
ZeroVector< float > FZeroVector
Definition: Vector.hpp:1604
SparseVector< double > SparseDVector
An unbounded sparse vector holding floating point values of type double.
Definition: Vector.hpp:1707
ScalarVector< float > FScalarVector
Definition: Vector.hpp:1599
Vector< long > LVector
An unbounded dense vector holding signed integers of type long.
Definition: Vector.hpp:1692
CVector< unsigned long, 3 > Vector3UL
A bounded 3 element vector holding unsigned integers of type unsigned long.
Definition: Vector.hpp:1672
The namespace of the Chemical Data Processing Library.
Definition: TypeTraits.hpp:179