#include <cassert>
#include <cstring>
+#include <iterator>
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
namespace llvm {
/// SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
template<typename PtrTy>
class SmallPtrSetIterator : public SmallPtrSetIteratorImpl {
+ typedef PointerLikeTypeTraits<PtrTy> PtrTraits;
+
public:
+ typedef PtrTy value_type;
+ typedef PtrTy reference;
+ typedef PtrTy pointer;
+ typedef std::ptrdiff_t difference_type;
+ typedef std::forward_iterator_tag iterator_category;
+
explicit SmallPtrSetIterator(const void *const *BP)
: SmallPtrSetIteratorImpl(BP) {}
// Most methods provided by baseclass.
const PtrTy operator*() const {
- return static_cast<const PtrTy>(const_cast<void*>(*Bucket));
+ return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
}
inline SmallPtrSetIterator& operator++() { // Preincrement
struct NextPowerOfTwo {
enum { Val = NextPowerOfTwoH<N, (N&(N-1)) == 0>::Val };
};
-
+
/// SmallPtrSet - This class implements a set which is optimizer for holding
/// SmallSize or less elements. This internally rounds up SmallSize to the next
// Make sure that SmallSize is a power of two, round up if not.
enum { SmallSizePowTwo = NextPowerOfTwo<SmallSize>::Val };
void *SmallArray[SmallSizePowTwo];
+ typedef PointerLikeTypeTraits<PtrType> PtrTraits;
public:
SmallPtrSet() : SmallPtrSetImpl(NextPowerOfTwo<SmallSizePowTwo>::Val) {}
SmallPtrSet(const SmallPtrSet &that) : SmallPtrSetImpl(that) {}
/// insert - This returns true if the pointer was new to the set, false if it
/// was already in the set.
- bool insert(PtrType Ptr) { return insert_imp(Ptr); }
+ bool insert(PtrType Ptr) {
+ return insert_imp(PtrTraits::getAsVoidPointer(Ptr));
+ }
/// erase - If the set contains the specified pointer, remove it and return
/// true, otherwise return false.
- bool erase(PtrType Ptr) { return erase_imp(Ptr); }
+ bool erase(PtrType Ptr) {
+ return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
+ }
/// count - Return true if the specified pointer is in the set.
- bool count(PtrType Ptr) const { return count_imp(Ptr); }
+ bool count(PtrType Ptr) const {
+ return count_imp(PtrTraits::getAsVoidPointer(Ptr));
+ }
template <typename IterT>
void insert(IterT I, IterT E) {