Ignore:
Timestamp:
Mar 5, 2007, 10:45:32 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Fixes #155. Added asserts to check vectors in all non-const functions since no inline functions exists anymore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/vector.h

    r782 r783  
    6363     \par
    6464     Currently there is no restriction on how a vector is used when
    65      the vector is a const view into another vector or
    66      matrix. To avoid unexpected runtime errors, the programmer must
    67      declare const view vectors as const in order to get compile time
    68      diagnostics about improper use of a const view vector object. An
    69      example of improper use of a const view vector is assignment of
    70      values to an element in the object. If the const view object was
    71      declared const the assigment will be caught by the compiler
    72      whereas it will cause a (un-catchable) runtime error. Example:
     65     the vector is a const view into another vector or matrix. To
     66     avoid unexpected runtime errors, the programmer must declare
     67     const view vectors as 'const' in order to get compile time
     68     diagnostics about improper use of a const view vector object. If
     69     'const' is not used and the const view vector is used erroneously
     70     (such as on the left hand side in assignments), the compiler will
     71     not catch the error and runtime error will occur. assert(3) is
     72     used to catch the runtime error during development. Example on
     73     bad and proper use of const view vectors:
    7374     @code
    7475  const vector vm(13,1.0);
    7576  vector v1(vm,2,4);       // bad code! not const!
    7677  v1(0)=-123;              // accepted by compiler, runtime abort will occur
     78                           // or catched by assert depending on compiler flags
    7779  const vector v2(vm,2,4); // proper code
    7880  v2(0)=-123;              // not acceptable for the compiler
     
    415417    gsl_vector_const_view* view_const_;
    416418    // proxy_v_ is used to access the proper underlying v_ or v_const_
    417     // in all const member functions.
     419    // in all const member functions. It is not used by design for
     420    // non-const vector functions and operators. This is to make sure
     421    // that runtime errors occur if a const vector is used in an
     422    // inappropriate manner such as on left hand side in assignment
     423    // (remember, v_ is null for const vector views).
    418424    const gsl_vector* proxy_v_;
    419425  };
Note: See TracChangeset for help on using the changeset viewer.