std::vector<T> Vect;
};
+ // No copy constructor or copy assignment. Use clone() with move assignment.
CopyOnWriteVector(const CopyOnWriteVector &V) LLVM_DELETED_FUNCTION;
+ void operator=(const CopyOnWriteVector &V) LLVM_DELETED_FUNCTION;
public:
- CopyOnWriteVector() : Data(0) {}
- CopyOnWriteVector(CopyOnWriteVector &&V) : Data(V.Data) { V.Data = 0; }
+ CopyOnWriteVector() : Data(nullptr) {}
+ CopyOnWriteVector(CopyOnWriteVector &&V) : Data(V.Data) { V.Data = nullptr; }
~CopyOnWriteVector() { destroy(); }
// Returns true if this holds a valid vector.
- bool valid() { return Data; }
+ bool valid() const { return Data; }
// Returns true if this vector is writable.
- bool writable() { return Data && Data->NumRefs == 1; }
+ bool writable() const { return Data && Data->NumRefs == 1; }
// If this vector is not valid, initialize it to a valid vector.
void init() {
delete Data;
else
--Data->NumRefs;
- Data = 0;
+ Data = nullptr;
}
// Make this vector writable, creating a copy if needed.
// Create a lazy copy of this vector.
CopyOnWriteVector clone() { return CopyOnWriteVector(Data); }
- // No copy constructor or copy assignment. Use clone() with move assignment.
- void operator=(const CopyOnWriteVector &V) LLVM_DELETED_FUNCTION;
-
- void operator=(CopyOnWriteVector &&V) {
+ CopyOnWriteVector &operator=(CopyOnWriteVector &&V) {
destroy();
Data = V.Data;
- V.Data = 0;
+ V.Data = nullptr;
+ return *this;
}
- typedef typename std::vector<T>::const_iterator iterator;
+ typedef typename std::vector<T>::const_iterator const_iterator;
const std::vector<T> &elements() const { return Data->Vect; }
- iterator begin() const { return elements().cbegin(); }
- iterator end() const { return elements().cend(); }
+ const_iterator begin() const { return elements().cbegin(); }
+ const_iterator end() const { return elements().cend(); }
const T& operator[](unsigned i) const { return elements()[i]; }
unsigned size() const { return Data ? elements().size() : 0; }
// Return true if V and this vector refer to the same data.
- bool sameAs(const CopyOnWriteVector& V) { return Data == V.Data; }
+ bool sameAs(const CopyOnWriteVector &V) const { return Data == V.Data; }
// Clear vector. The vector must be writable.
void clear() {
}
// Push a new element onto the end. The vector must be writable.
- void push_back(const T& Elem) {
+ void push_back(const T &Elem) {
assert(writable() && "Vector is not writable!");
Data->Vect.push_back(Elem);
}