Changeset 1706 for trunk


Ignore:
Timestamp:
Jan 8, 2009, 10:36:27 PM (12 years ago)
Author:
Peter
Message:

implementing swap function

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/matrix_weighted_test.cc

    r1487 r1706  
    22
    33/*
    4   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2008, 2009 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3232void test_constructor_const(test::Suite& suite);
    3333void test_constructor_matrix(test::Suite& suite);
     34void test_swap(test::Suite& suite);
    3435
    3536int main(int argc, char* argv[])
     
    4041  test_constructor_const(suite);
    4142  test_constructor_matrix(suite);
     43  test_swap(suite);
    4244
    4345  suite.return_value();
     
    9294}
    9395
     96void test_swap(test::Suite& suite)
     97{
     98  MatrixWeighted x(3,10);
     99  MatrixWeighted y(0,0);
     100  x.swap(y);
     101  suite.add(x.columns()==0);
     102  suite.add(x.rows()==0);
     103  suite.add(y.columns()==10);
     104  suite.add(y.rows()==3);
     105}
    94106
     107
  • trunk/yat/utility/MatrixWeighted.cc

    r1589 r1706  
    66  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    77  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    167168
    168169
     170  void MatrixWeighted::swap(MatrixWeighted& other)
     171  {
     172    std::swap(vec_, other.vec_);
     173    std::swap(columns_, other.columns_);
     174  }
     175
     176
    169177  void MatrixWeighted::resize(size_t rows, size_t columns)
    170178  {
     
    199207  }
    200208
     209
     210  void swap(MatrixWeighted& lhs, MatrixWeighted& rhs)
     211  {
     212    lhs.swap(rhs);
     213  }
     214
    201215}}} // of namespace utility, yat and thep
  • trunk/yat/utility/MatrixWeighted.h

    r1589 r1706  
    99  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    1010  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     11  Copyright (C) 2009 Peter Johansson
    1112
    1213  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    114115   
    115116    /**
    116        \brief The istream constructor.
     117       \brief constructor.
    117118
    118119       Data is copied from \a other and weights are calculated using
     
    210211
    211212    /**
     213       \brief swap objects
     214
     215       Takes constant time. Invalidates iterators.
     216     */
     217    void swap(MatrixWeighted& other);
     218
     219    /**
    212220       \brief Resize Matrix
    213221
     
    258266     Takes constant time.
    259267
    260      \throw std::runtime_error if the two matrices disagree in size.
     268     \see MatrixWeighted::swap(MatrixWeighted&)
    261269  */
    262270  void swap(MatrixWeighted&, MatrixWeighted&);
Note: See TracChangeset for help on using the changeset viewer.