Browse code

Fixed warnings and suggestions in Matrix data struct

Tiger Gao authored on 04/06/2018 20:22:07
Showing 1 changed files

... ...
@@ -138,15 +138,18 @@ template <class Parser>
138 138
 RowMatrix::RowMatrix(Parser &p, unsigned nrow, std::vector<unsigned> whichCols)
139 139
 {
140 140
     // TODO implement
141
-    for (unsigned i = 0; i < mNumRows; i++) {
141
+    for (unsigned i = 0; i < mNumRows; ++i)
142
+    {
142 143
         mRows.push_back(Vector(whichCols.size()));
143 144
     }
144 145
 
145
-    while (p.hasNext()) {
146
+    while (p.hasNext())
147
+    {
146 148
         MatrixElement e(p.getNext());
147
-        auto newColsIndex = std::find(whichCols.begin(), whichCols.end(), e.col);
148
-        if (newColsIndex != whichCols.end()) {
149
-            this->operator()(e.row, newColsIndex - whichCols.begin()) = e.value;
149
+        std::vector<unsigned>::iterator newColsIndex = std::find(whichCols.begin(), whichCols.end(), e.col);
150
+        if (newColsIndex != whichCols.end())
151
+        {
152
+            this->operator()(e.row, std::distance(whichCols.begin(), newColsIndex)) = e.value;
150 153
         }
151 154
     }
152 155
 }
... ...
@@ -155,15 +158,18 @@ template <class Parser>
155 158
 ColMatrix::ColMatrix(Parser &p, unsigned nrow, std::vector<unsigned> whichCols)
156 159
 {
157 160
     // TODO implement
158
-    for (unsigned j = 0; j < whichCols.size(); j++) {
161
+    for (unsigned j = 0; j < whichCols.size(); ++j)
162
+    {
159 163
         mCols.push_back(Vector(mNumRows));
160 164
     }
161 165
 
162
-    while(p.hasNext()) {
166
+    while(p.hasNext())
167
+    {
163 168
         MatrixElement e(p.getNext());
164
-        auto newColsIndex = std::find(whichCols.begin(), whichCols.end(), e.col);
165
-        if (newColsIndex != whichCols.end()) {
166
-            this->operator()(e.row, newColsIndex - whichCols.begin()) = e.value;
169
+        std::vector<unsigned>::iterator newColsIndex = std::find(whichCols.begin(), whichCols.end(), e.col);
170
+        if (newColsIndex != whichCols.end())
171
+        {
172
+            this->operator()(e.row, std::distance(whichCols.begin(), newColsIndex)) = e.value;
167 173
         }
168 174
     }
169 175
 }