Boost logo

Boost :

From: Powell, Gary (powellg_at_[hidden])
Date: 2004-03-09 16:55:15


No, but just because the standard libraries scr*wed up is no reason to perpetuate the mistake.

It's the rule of unexpected consequences.

Is
circular_buffer<int> x = { 1, 2, 3};
circular_buffer<short> y = { 1, 2 ,3};

x == y ?? or not?

Sure looks like it should work.

The VTL library does it IMO correctly, allowing that if there is an operation
T1 F T2, then

V1 F V2 compiles. Otherwise you just force the user to write what should be library
code.

(Obviously swap can't do this unless the Allocators are the same.)

template<class T1, class T2, class Alloc>
void swap( circular_buffer<T1, Alloc> &lhs, circular_buffer<T2, Alloc> &rhs)
{
   // do an element by element swap.
   // and insert for the leftover elements.
}

template<class T1, class Alloc>
void swap<T1, T1, Alloc> ( circular_buffer<T1, Alloc> &lhs, circular_buffer<T1, Alloc> &rhs)
{
   // swap the whole container.
   lhs.swap(rhs);
}

  Yours,
  -Gary-

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Pavel Vozenilek
Sent: Tuesday, March 09, 2004 11:52 AM
To: boost_at_[hidden]
Subject: [boost] Re: Formal Review: Circular Buffer

"Powell, Gary" <powellg_at_[hidden]> wrote

> Shouldn't the comparison functions allow the types to differ?
>
> circular_buffer<T, MyAlloc> x;
> circular_buffer<S, YourAlloc> y;
>
> bool b = x == y; for where the operator T == S is valid?
> And what does the allocator have to do with it?
>
Hmm, do you know a STL implementation/some container
with this feature? It may be often bug to compare containers with
different types.

/Pavel

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk