[ create a new paste ] login | about

Link: http://codepad.org/yZs7gMD8    [ raw code | output | fork ]

C++, pasted on Mar 22:
#include <iostream>

void file_copy(const char *from, const char *to)
{
	std::cout << "file_copy: " << from << " -> " << to << std::endl;
}

namespace A
{
	enum FromTo
	{
		FROM, TO
	};

	template <FromTo lhs, FromTo rhs> inline void copy(const char *lhs, const char *rhs);

	template <> inline void copy<FROM, TO>(const char *lhs, const char *rhs)
	{
		file_copy(lhs, rhs);
	}

	template <> inline void copy<TO, FROM>(const char *lhs, const char *rhs)
	{
		file_copy(rhs, lhs);
	}
}


namespace B
{
	struct From
	{
		inline explicit From(const char *file) : file(file)
		{
		}

		const char *file;
	};

	struct To
	{
		inline explicit To(const char *file) : file(file)
		{
		}

		const char *file;
	};

	inline void copy(const From &from, const To &to)
	{
		file_copy(from.file, to.file);
	}

	inline void copy(const To &to, const From &from)
	{
		file_copy(from.file, to.file);
	}
}


int main(void)
{
	const char *from = "from", *to = "to";

	{
		using namespace A;

		copy<FROM, TO>(from, to);
		copy<TO, FROM>(to, from);
	}

	{
		using namespace B;

		copy(From(from), To(to));
		copy(To(to), From(from));
	}

	return 0;
}


Output:
1
2
3
4
file_copy: from -> to
file_copy: from -> to
file_copy: from -> to
file_copy: from -> to


Create a new paste based on this one


Comments: