#ifndef NALL_GROUP_HPP #define NALL_GROUP_HPP //group //vector of unique references #include namespace nall { template struct group : protected vector { group& operator=(const group& source) { vector::operator=(source); return *this; } group& operator=(group&& source) { vector::operator=(std::move(source)); return *this; } template group(Args&&... args) { construct(std::forward(args)...); } bool empty() const { return vector::empty(); } unsigned size() const { return vector::size(); } void reset() { vector::reset(); } T& first() const { return *vector::operator[](0); } //return true if at least one item was appended template bool append(T& value, Args&&... args) { bool result = append(value); return append(std::forward(args)...) | result; } bool append(T& value) { if(vector::find(&value)) return false; return vector::append(&value), true; } //return true if at least one item was removed template bool remove(T& value, Args&&... args) { bool result = remove(value); return remove(std::forward(args)...) | result; } bool remove(T& value) { if(auto position = vector::find(&value)) return vector::remove(position()), true; return false; } struct iterator : protected vector::constIterator { T& operator*() const { return *vector::constIterator::operator*(); } bool operator!=(const iterator& source) const { return vector::constIterator::operator!=(source); } iterator& operator++() { vector::constIterator::operator++(); return *this; } iterator(const group& source, unsigned position) : vector::constIterator(source, position) {} }; const iterator begin() const { return iterator(*this, 0); } const iterator end() const { return iterator(*this, size()); } private: void construct() {} void construct(const group& source) { vector::operator=(source); } void construct(group&& source) { vector::operator=(std::move(source)); } template void construct(T& value, Args&&... args) { append(value); construct(std::forward(args)...); } }; } #endif