Conditional C++ Sequence Methods

The following conditional C++ methods apply the object's Boolean sequence to the input sequence(s). These methods are of the following types:

The operation can be one of the following:

Sequence<R> iif(Sequence<R> const& then, Sequence<R> const& else) const

 

Choose the element of the then sequence or the else sequence depending on the boolean value of the element of the object's condition sequence. All three sequences are traversed at the same speed (if the element of the then sequence is used, then the element of else sequence is skipped and visa versa). (Please see the Ternary Operations page for further details.)
Sequence<R> cond(Sequence<R> const& then, Sequence<R> const& otherwise) const Choose the element of the then sequence or the else sequence depending on the boolean value of the element of the object's condition sequence. Unlike iif(), the position in the sequence not used is not changed. (Please see the Ternary Operations page for further details.)
Sequence<T> filter(Sequence<mco_seq_bool> const& condition) const Returns a sequence of the same type with only the elements corresponding to true elements in the object's condition sequence
Sequence<mco_seq_no_t> filterPos() const Returns an integer sequence with the positions of the true elements in the object's sequence

Example

Following is an example code snippet demonstrating a conditional method:

     
    {
        mco_trans_h trans;
        mco_cursor_t quote_cursor;
        Quote quote;
        mco_date last;
        MCO_RET rc;
        ...
        rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans);
        if ( MCO_S_OK == rc )
        {
         
            for (rc = mco_cursor_first(trans, &quote_cursor); 
                rc != MCO_S_CURSOR_END; 
                rc = mco_cursor_next(trans, &quote_cursor)) 
            {
                quote.from.cursor(trans, &quote_cursor);
                 
                // Select the interval
                Sequence<uint4> day_iterator;
                quote.day_last(&last);
                quote.day_search(day_iterator, DMY(1, MONTH(last), YEAR(last)), 
                    MCO_SEQ_BOUNDARY_INCLUSIVE, last, MCO_SEQ_BOUNDARY_INCLUSIVE));
 
                // Display the days of last month when close > open
                print_sequence(quote, day_iterator.filter(quote.close_project(day_iterator) > 
                            quote.open_project(day_iterator)));
            }
            mco_trans_rollback(trans);
        }
    }