incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Pevtsov" <Ant...@moscow.vdiweb.com>
Subject RE: test for lib.string.swap
Date Thu, 18 May 2006 14:52:12 GMT
Martin Sebor wrote:
[...]
>    UserAlloc<double> xx (x);
>     UserAlloc<int> xxx (xx);
>
>     assert (x == xxx);
>}

Here is another question. We use template class Allocator in the tests,
and it assumes that code should be valid for std:allocator too.
But 

SharedAlloc a;
Allocator<int> z (&a);

wll not compile when Allocator is std::allocator. Is there any way to
use std::allocator and UserAlloc together (at the same time UserAlloc
objects should be not equal)?


Thanks,
Anton Pevtsov


-----Original Message-----
From: Martin Sebor [mailto:sebor@roguewave.com] 
Sent: Wednesday, May 17, 2006 20:17
To: stdcxx-dev@incubator.apache.org
Subject: Re: test for lib.string.swap


Anton Pevtsov wrote:
> Martin, I updated all tests to use new macro 
> DEFINE_STRING_TEST_DISPATCH and allocator. The diff file is here:
> http://people.apache.org/~antonp/stdcxx05172006/

Thanks for doing that! Please go ahead and apply the changes.

> 
> Martin Sebor wrote:
> 
>> <>PS I noticed that the --no-xxx/--enable-xxx command line options 
>> don't
> 
> 
>> <>quite control the overloads they should. I haven't looked into it 
>> very closely yet except for adding a missing "-enable-xxx" > string. 
>> Are you seeing the same thing on your end?
>>
> 
> Yes. The cause is the missed option "-no-self-ref". The diff file with

> fix attached.

Aha! Let me apply this one.

> 
> I have a question about UserAlloc: how can I instantiate two different

> allocators (i.e. allocators which have different ids)? It looks like 
> all allocators in the same scope will have the same id.

Good question! All default-constructed allocators (regardless of their
value_type) share the same SharedAlloc object and thus have the same id.
The same specializations also compare equal. To construct a UserAlloc
object that uses a different SharedAlloc object you must create it and
point the allocator at it. Here's how to do it:

#include <cassert>
#include <rw_allocator.h>

int main ()
{
     SharedAlloc a;

     UserAlloc<int> x;
     UserAlloc<int> y;
     UserAlloc<int> z (&a);

     assert (x == y);
     assert (x != z);

     // copies of the same object have the same id regardless
     // of their type
     UserAlloc<double> xx (x);
     UserAlloc<int> xxx (xx);

     assert (x == xxx);
}

Mime
View raw message