Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeEnum in std.variant #9975

Open
dlangBugzillaToGithub opened this issue May 21, 2013 · 1 comment
Open

TypeEnum in std.variant #9975

dlangBugzillaToGithub opened this issue May 21, 2013 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

diggsey reported this on 2013-05-21T01:24:15Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=10127

Description

It would be useful to use the tag part of a tagged union on its own, and it would fit in well with the rest of std.variant.

It's not always the case that you want to store actual data, sometimes you just need to store the type. Also sometimes you need to store the data somewhere else or store it in such a way that you can specify the type first and fill in the data later.

eg.
	alias TypeEnum!(
		void,
		byte,
		short,
		string,
		Object
	) TestTypeEnum;
	
	TestTypeEnum test;
	
	assert(test == TestTypeEnum.from!void);
	assert(test != TestTypeEnum.from!byte);
	
	test = TestTypeEnum.from!string;
	
	assert(test == TestTypeEnum.from!string);
	assert(test != TestTypeEnum.from!Object);
	
	static assert(!__traits(compiles, TestTypeEnum.from!float));

(pull request shortly)
@dlangBugzillaToGithub
Copy link
Author

diggsey commented on 2013-05-21T01:27:18Z

https://github.com/D-Programming-Language/phobos/pull/1298

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants