3

I get the error

../src/internet-stack/mp-tcp-socket-impl.cc: In member function ‘void ns3::MpTcpSocketImpl::OpenCWND(uint8_t, uint32_t)’:
../src/internet-stack/mp-tcp-socket-impl.cc:2471: error: no match for ‘operator-’ in ‘sFlow->ns3::MpTcpSubFlow::measuredRTT.std::multiset<_Key, _Compare, _Alloc>::end [with _Key = double, _Compare = std::less<double>, _Alloc = std::allocator<double>]() - 1’
/usr/include/c++/4.4/bits/stl_bvector.h:179: note: candidates are: ptrdiff_t std::operator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)

because I tried:

  double maxrttval = *(sFlow->measuredRTT.end() - 1);

now, in the same code double baserttval = *(sFlow->measuredRTT.begin()); works perfectly well.

I can't understand what is wrong . I have to access the last element just like I accessed the first element. Thanks for help .

3 Answers3

0

The iterator category of multiset is BidirectionalIterator, which does not support operator+ nor operator-, they're only supported by RandomAccessIterator. But it supports operator--, so you can:

double maxrttval = *(sFlow->measuredRTT.end()--);

And you can get the last element by reverse iterator too:

double maxrttval = *(sFlow->measuredRTT.rbegin());
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
0

If you want to access the last item of the multiset use std::multiset::rbegin():

Return reverse iterator to reverse beginning Returns a reverse iterator pointing to the last element in the container (i.e., its reverse beginning).

Reverse iterators iterate backwards: increasing them moves them towards the beginning of the container.

rbegin points to the element preceding the one that would be pointed to by member end.

So use

double maxrttval = *(sFlow->measuredRTT.rbegin());
Alex Lop.
  • 6,810
  • 1
  • 26
  • 45
0

Why don't you use std::advance?

it = sFlow->measuredRTT.end();
std::advance(it, -1);
double maxrttval = *it;
camar
  • 1