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

[feature] Enum classes "count". #57

Closed
p-groarke opened this issue Feb 18, 2020 · 3 comments
Closed

[feature] Enum classes "count". #57

p-groarke opened this issue Feb 18, 2020 · 3 comments
Labels
feature new feature request

Comments

@p-groarke
Copy link
Contributor

I don't know how much effort this would take, but if it is too much don't worry about it. I understand you maintain this for fun on your free time.

One of my only gripes with mx is the lack of count enum class members.

In my experience, it is often best practice to add a trailing count enum, which enables you to write generalized loops on enums without ever worrying about size problems. For ex.

enum class potato {
    russet,
    yukon,
    sweet,
    count, // This will always be equal to the number of enum elements, if they aren't specified values.
};

So I can do.

for (size_t i = 0; i < size_t(potato::count); ++i) {
    potato my_potato = potato(i); //etc
}

So, in mx. I wish there was a count where it makes sense. For ex with Step.

    	enum class Step
    	{
    		c = 0,
    		d = 1,
    		e = 2,
    		f = 3,
    		g = 4,
    		a = 5,
    		b = 6,
    		count,
            unspecified = -1
    	};

Cheers

@webern
Copy link
Owner

webern commented Feb 22, 2020

Do you have need of such loops currently, or is this more of an aesthetic preference?

@webern webern added the feature new feature request label Feb 26, 2020
@p-groarke
Copy link
Contributor Author

Yes I do, but so far only for Mx::Step.

@webern
Copy link
Owner

webern commented Feb 29, 2020

Ok, that makes sense. Step is arguably a numerical concept anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature request
Projects
None yet
Development

No branches or pull requests

2 participants