全enumが泣いた

どうもC++enumは使いにくいときがあって困る。

たとえばseek関数を作るときに

	enum seek_option
	{
		...
		seek_end,
		...
	};

	class file
	{
		...
		void seek(unsigned long offset,seek_option option);
		...
	};

	file f;
	f.seek(100,seek_option::seek_end);


といった感じで使いたい。ところがseek_option::seek_endという使い方は非標準だしダメダメと警告がでる(VS2005)

えー・・と思いつつ一瞬脳内で思いついたのが

	struct seek_option
	{
		...
		static const int seek_end=3,
		...
	};


でもこれじゃあseek関数のプロトタイプと合わないね・・

こんなときこそtag dispatchなのかしら・・・

	template <int i>
	struct int_to_type
	{
		enum{value=i};
	};

	struct seek_option
	{
		...
		typedef int_to_type<3> seek_end;
		...
	};

	class file
	{
		...
		void seek(unsigned long offset,seek_option::seek_end option);
		...
	};

	file f;
	f.seek(100,seek_option::seek_end());


これが一番ましかなぁ。

int_to_typeの中身がenumだけになんかだまされてるような気がw