Boost logo

Boost :

From: Alisdair Meredith (alisdair.meredith_at_[hidden])
Date: 2002-02-06 04:48:12


OK, finally found time to download the source :* ) [Confession: it has taken a while to get Yahoo groups working correctly]

Having recently read Herb Sutter's 'Exceptional C++' I was keen to take a look at the swap specialization, as I was not sure how this would work. Neat, I discover a new std algorithm for just these occasions! However...

  template <std::size_t N2>
  void swap(fixed_capacity_vector<T, N2>& x) {
    if (size() > N2 || x.size() > N)
      throw std::range_error("fixed_capacity_vector");
    if (size() <= x.size()) {
      size_type d = x.size() - size();
      std::swap_ranges(begin(), end(), x.begin());
      insert(end(), x.begin() + size(), x.end());
      x.erase(x.end() - d, x.end());
    } else {
      size_type d = size() - x.size();
      std::swap_ranges(x.begin(), x.end(), begin());
      x.insert(x.end(), begin() + x.size(), end());
      erase(end() - d, end());
    }
  }

I believe both calls to insert can fail on copy-constructors, and leave you with a modified container [so breaking the exception guarantees]

Not sure how to fix this [or if it is fixable] but it should at least be documented. I expect [no timing tests done] that this also means swapping fixed_vectors should be significantly slower than std::vectors. Given the relative infrequency of swapping the containers, the tradoff is likely worthwhile, but again worth noting [after measurements!]

AlisdairM

>>> wistaria_at_[hidden] 5 February 2002 12:57:31 >>>

I've just uploaded my new version of fixed_capacity_vector and others:

  http://groups.yahoo.com/group/boost/files/fixed_capacity/

...

Any comments/suggestions are welcome.

----------------------------------------------------------------------

For further information on Renault F1 visit our web site at www.renaultf1.com. This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please destroy and notify Renault F1 on +44 1608678000."

----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk