Topic: Are unequal allocators not copy constructible?
Author: "Bo Persson" <bop@gmb.dk>
Date: Tue, 6 Oct 2009 12:58:19 CST Raw View
I feel a slight inconsistency in requirements coming up. :-(
Consider this code:
template<class Type>
class unequal_allocator : public std::allocator<Type>
{
public:
// possibly overrides allocate and destroy
};
template<class Type>
bool operator==(const unequal_allocator<Type>& Left,
const unequal_allocator<Type>& Right)
{ return &Left == &Right; }
template<class Type>
bool operator!=(const unequal_allocator<Type>& Left,
const unequal_allocator<Type>& Right)
{ return !(Left == Right); }
unequal_allocator<some_type> a;
unequal_allocator<some_type> b(a);
The intention is to have an allocator where each instance is unique.
However, this fails the requirement that b==a after the second
constructor, which is present in Table 40 in both N2960 and N2946.
This was also present as an axiom in the CopyConstructible concept:
axiom CopyPreservation(T x) {
T(x) == x;
}
The copy must compare equal to the original!
Does this mean that my allocator is not copy constructible? Or must it
acquire its "uniqueness" sometimes after the construction?
Bo Persson
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]