Beispiel #1
0
typename IndexContainer::iterator sort_indices( const Container &v , IndexContainer &idx )
{
    idx.resize( v.size() );
    for( size_t i = 0 ; i != idx.size() ; ++i ) idx[i] = i;

    auto iter = std::partition( idx.begin() , idx.end() ,
                                [&v]( size_t i ) { return std::isfinite( v[i] ); } );
    std::sort( idx.begin() , iter , [&v]( size_t i1 , size_t i2 ) { return ( v[i1] < v[i2] ); } );
    return iter;
}
  // remove all elements = val
  void erase(T const& val)
  {
    size_type counter;
    typename std::vector<T>::iterator pos;
    for (difference_type i = m_offsets.size()-2; i>=0; --i)
    {
      for (difference_type j = m_offsets[i+1]-m_offsets[i]-1; j>=0; --j)
      {
        pos = m_data.begin() + m_offsets[i] + j;
        if (*pos == val)
        {
          m_data.erase(pos);
          for (int k = i+1; k < m_offsets.size(); ++k)
            --m_offsets[k];
        }

      }
    }
  }
  // insert new column if necessary
  T& operator() (size_type row, size_type col)
  {
    size_type const sr = size(row);
    if (col < sr)
      return m_data[ m_offsets[row] + col];
    else
    {
      Int const n_new = col - sr + 1;
      typename std::vector<T>::iterator pos = m_data.begin() + m_offsets[row+1];
      
      if (m_data.end()-pos < 0) // pos never can be greater than m_data.end(), otherwise m_offsets is wrong
        throw;
      m_data.insert(pos, n_new, T());

      for (size_type k = row+1; k < m_offsets.size(); ++k)
        m_offsets[k] += n_new;
      return m_data[ m_offsets[row] + col];
    }
  }
 size_type numRows() const
 { return m_offsets.size()-1; }