Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
template inline T &QVector::operator[](int i)
{ Q_ASSERT_X(i >= 0 && i < d->size, "QVector::operator[]", "index out of range");
return data()[i]; }
template inline T &QList::operator[](int i)
{ Q_ASSERT_X(i >= 0 && i < p.size(), "QList::operator[]", "index out of range");
detach(); return reinterpret_cast<Node *>(p.at(i))->t(); }
--- std_vector/main.cpp 2011-06-17 19:06:15.000000000 +0300
+++ std_vector_mod/main.cpp 2011-06-17 23:37:43.000000000 +0300
@@ -151,10 +151,11 @@
void matrixMultByVector(const std::vector<int> &ig, const std::vector<int> &jg, const std::vector<double> &ggl, const std::vector<double> &di,
const std::vector<double> &ggu, const std::vector<double> &vector, std::vector<double> &result)
{
- for(size_t i = 0; i < result.size(); i++)
+ int N = result.size();
+ for(int i = 0; i < N; i++)
result[i] = vector[i]*di[i];
- for(size_t i = 0; i < result.size(); i++)
+ for(int i = 0; i < N; i++)
for(int j = ig[i]; j < ig[i + 1]; j++)
{
result[i] += vector[jg[j]]*ggl[j];size_type
size() const
{ return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
Довольно странное решение.
reference
operator[](difference_type __n) const
{ return *(*this + __n); }
_Self&
operator+=(difference_type __n)
{
const difference_type __offset = __n + (_M_cur - _M_first);
if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
_M_cur += __n;
else
{
const difference_type __node_offset =
__offset > 0 ? __offset / difference_type(_S_buffer_size())
: -difference_type((-__offset - 1)
/ _S_buffer_size()) - 1;
_M_set_node(_M_node + __node_offset);
_M_cur = _M_first + (__offset - __node_offset
* difference_type(_S_buffer_size()));
}
return *this;
}
_Self
operator+(difference_type __n) const
{
_Self __tmp = *this;
return __tmp += __n;
}g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I/opt/QtSDK/Desktop/Qt/473/gcc/mkspecs/linux-g++ -I../../arrays_vs_containers/qvector -I/opt/QtSDK/Desktop/Qt/473/gcc/include/QtCore -I/opt/QtSDK/Desktop/Qt/473/gcc/include -I. -I../../arrays_vs_containers/qvector -I. -o main.o ../../arrays_vs_containers/qvector/main.cpp
g++ -Wl,-O1 -Wl,-rpath,/opt/QtSDK/Desktop/Qt/473/gcc/lib -o qvector main.o -L/opt/QtSDK/Desktop/Qt/473/gcc/lib -lQtCore -lpthread vector&
operator=(vector&& __x)
{
// NB: DR 675.
this->clear();
this->swap(__x);
return *this;
}operator()(int i, int j) { return arr[i + j * n]; } чтобы писать v(i,j). Вообще, вам, насколько я понимаю, фактически не нужен std::vector, вы ведь не меняете размер массива, всегда можно сделать более тонкую обёртку и её использовать, всё-таки у std::vector назначение немного другое.Есть такое свойство локальности ссылок — свойство программ повторно/часто обращаться к одним и тем же объектам; и имеет место временная (temporal) локализация и пространственная (spatial) локализация. Кэширование идет с упреждением, и на этом основании есть смысл обращаться по последовательным адресам, чтобы избежать промахов по кэшу.
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I/opt/QtSDK/Desktop/Qt/473/gcc/mkspecs/linux-g++ -I../../arrays_vs_containers/std_vector -I/opt/QtSDK/Desktop/Qt/473/gcc/include/QtCore -I/opt/QtSDK/Desktop/Qt/473/gcc/include -I. -I../../arrays_vs_containers/std_vector -I. -o main.o ../../arrays_vs_containers/std_vector/main.cpp
g++ -Wl,-O1 -Wl,-rpath,/opt/QtSDK/Desktop/Qt/473/gcc/lib -o std_vector main.o -L/opt/QtSDK/Desktop/Qt/473/gcc/lib -lQtCore -lpthread Распространение в бинарниках под оба компилятора
Массивы против контейнеров в задачах матмоделирования