I think that you will have a problem creating a class that stores references such that they can be added and removed. You can have members of reference type or a reference to a pointer, but not a container of references or a pointer to a reference. However, if you have a container of (smart) pointers, you could implement what manasij7479 mentioned.
Yes, that's what I'm trying to achive:
Code:
class container {
public:
using iterator=typename std::vector<std::reference_wrapper<argument>>::iterator; // won't work
using const_iterator=typename std::vector<std::reference_wrapper<argument>>::const_iterator; // won't work
iterator begin() noexcept; // calling `*begin()' would resolve into `std::reference_wrapper<argument>' instead of `argument'
const_iterator begin() const noexcept;
iterator end() noexcept; // same as `begin()'
const_iterator end() const noexcept;
private:
std::vector<std::reference_wrapper<argument>> m_arguments;
};
Thus, one still has to deal with raw pointers, smart pointers or reference wrappers within a range-based for loop:
Code:
container c;
for (auto& object:c) {
object.get().some_function(); // would be great to use `object.some_function()' instead
}