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

Previous/next value helpers #280

Closed
turol opened this issue Jun 6, 2023 · 4 comments
Closed

Previous/next value helpers #280

turol opened this issue Jun 6, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@turol
Copy link

turol commented Jun 6, 2023

There should be a way to get previous/next value in the enum, something like this:

https://github.com/turol/smaaDemo/blob/31ba838df401122afb62ebbf4c6b49c93108b011/demo/smaaDemo.cpp#L252

https://github.com/turol/smaaDemo/blob/31ba838df401122afb62ebbf4c6b49c93108b011/demo/smaaDemo.cpp#L2595

@Neargye
Copy link
Owner

Neargye commented Jun 6, 2023

For example

enum class SMAAEdgeMethod : uint8_t {
	  Color
	, Luma
	, Depth
};

nextValue(SMAAEdgeMethod::Depth) - occur error or return SMAAEdgeMethod::Color ?

https://en.cppreference.com/w/cpp/iterator/next for example throws an error (I would probably prefer to return optional)

@turol
Copy link
Author

turol commented Jun 6, 2023

In my case I cycle again to the beginning. You could of course add both variants.

@Neargye Neargye added this to the v0.9.2 milestone Jun 6, 2023
@Neargye Neargye self-assigned this Jun 6, 2023
@Neargye Neargye added the enhancement New feature or request label Jun 6, 2023
@turol
Copy link
Author

turol commented Jun 6, 2023

On further thinking there should probably be the following variants:

  1. cycle_prev/cycle_next does what I currently do.
  2. prev/next does what you suggested, throws exception
  3. prev_opt/next_opt returns a std::optional

This should cover every use case.

@Neargye Neargye modified the milestones: v0.9.2, 0.9.3 Jun 10, 2023
@Neargye
Copy link
Owner

Neargye commented Jun 12, 2023

Add 2 variants in master:

  • cycle_prev/cycle_next does what I currently do.
  • prev/next returns a std::optional

https://github.com/Neargye/magic_enum/blob/master/include/magic_enum_utility.hpp

@Neargye Neargye closed this as completed Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants