Skip to content

wahez/tagged

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tagged

Strong typedef for C++

Unlike many other strong typedefs, this supports implicit conversion between tagged types with the same tag, but a different underlying type. This feature also allows you to create tagged objects that contain a reference to an underlying type.

using meter = tagged<double, struct meter_tag>;

void print_meter(meter::cref m)
{
	std::cout << m.value() << "m" << std::endl;
}

int main()
{
	// passing a value of the underlying type with in a strongly typed way without copies
	int distance = 4;
	print_meter(as_ref<meter>(distance));

	using seconds = tagged<double, struct seconds_tag>;
	auto time = seconds(3.3);
	// print_meter(time); -> does not compile
}

It does at the moment not support iostreams or other operations.

About

Strong typedef for C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages