LINUX.ORG.RU

История изменений

Исправление eao197, (текущая версия) :

Если у вас C++14 или новее, то можно проще:

class Impl
	{
	public:
		Impl(const size_t v, const std::vector<int> &values) : m_idx(v), m_values(values) {}

		auto operator*() const { return m_values[m_idx]; }
		auto & operator++()
		{
			m_idx++;
			return *this;
		}
		bool operator!=(const Impl& rhs) const { return m_idx != rhs.m_idx; }

	private:
		// Тут может быть что угодно.
		size_t m_idx;
		const std::vector<int> &m_values;
	};

Исходная версия eao197, :

Если у вас C++14 или старше, то можно проще:

class Impl
	{
	public:
		Impl(const size_t v, const std::vector<int> &values) : m_idx(v), m_values(values) {}

		auto operator*() const { return m_values[m_idx]; }
		auto & operator++()
		{
			m_idx++;
			return *this;
		}
		bool operator!=(const Impl& rhs) const { return m_idx != rhs.m_idx; }

	private:
		// Тут может быть что угодно.
		size_t m_idx;
		const std::vector<int> &m_values;
	};