Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-04-05 06:35:10

"Alexander Nasonov" <alnsn-mycop_at_[hidden]> wrote
> Thorsten Ottosen wrote:
> >
> > its not global. And you have to include the specific assign/stl.hpp
> > header.

My problem with assignment lib is shown in following.
in a nutshell I might want to use assign , but not +=, from assignment lib.
Currently not possible.
Personally I dont like use of += function for init anyways.
Nevertheless for maps etc and matrices etc it might be useful.
OTOH Adding brackets to each initialiser for assign is a bit ugly... but
appreciate not much you can do about it.

Andy Little


#include <iostream>
#include <vector>
// stream output for vector of t
#include "test.hpp"
#include "pqs/pqs.hpp"

// if += used for another purpose cant use assign lib
// following cant both be true
#define USE_ASSIGN_LIB 0

#include "boost/assign.hpp"
using namespace boost::assignment; // bring asignment libs 'operator+=()'
into scope

// Dont want assignment lib += semantics,
// rather want to add a value to every element in a vector
template <typename T>
operator +=(std::vector<T>& vect, T t)
    std::vector<T>::iterator iter= vect.begin();
    while(iter != vect.end()){
        *iter += t;
    return vect;

using namespace pqs;
int main()
     std::vector<pqs::q_length::mm> v;
// ok cant use += assignment semantics here
// but maybe would like to use assign function
    assign( v ) (pqs::q_length::mm(1)),

    std::cout << v <<'\n';

#if USE_ARITH_PLUS_EQ // cant do this and use assignment lib
    v += q_length::mm(1);

    std::cout << v <<'\n';

Boost list run by bdawes at, gregod at, cpdaniel at, john at