
#include <iostream>
#include <vector>
using namespace std;

template<typename T>
class Svector : public vector<T>
{

	class SizeProxy
	{
	      public:
		Svector *parentRef()
		{
			return reinterpret_cast<Svector *>(
			  reinterpret_cast<char *>(this) -
			  offsetof(Svector<T>, count));
		}
		SizeProxy &operator=(size_t s)
		{
			parentRef()->resize(s);
			return *this;
		}

		operator size_t() { return parentRef()->size(); }
	};

	class RefProxy
	{
		T *ref;

	      public:
		RefProxy(T *r = nullptr)
		  : ref(r)
		{}

		RefProxy &operator=(const T &t)
		{
			if (ref)
				*ref = t;
			return *this;
		}

		RefProxy &operator=(T &&t)
		{
			if (ref)
				*ref = move(t);
			return *this;
		}

		operator T()
		{
			if (ref)
				return *ref;
			else
				return T();
		}
	};

      public:
	SizeProxy count;
	RefProxy operator[](size_t i)
	{
		if (i < this->size())
			return RefProxy(this->data() + i);
		else
			return RefProxy();
	}
};

template<class F, class... Args>
void
f2(F f, Args... a)
{
	f(a...);
	f(a...);
}

void
f(int i, float j)
{
	cout << i << endl;
	cout << j << endl;
}

int
main()
{
	Svector<int> a, s;
	s = a;
	s.count = 5;
	s.push_back(228);

	f2(f, 1, 2.7);

	cout << s[0] << endl;
	cout << s[5] << endl;
	cout << s[124] << endl;

	return 0;
}
