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

ambiguity about ofParameter<bool> constructor #7671

Closed
artificiel opened this issue Sep 21, 2023 · 0 comments · Fixed by #8132
Closed

ambiguity about ofParameter<bool> constructor #7671

artificiel opened this issue Sep 21, 2023 · 0 comments · Fixed by #8132

Comments

@artificiel
Copy link
Contributor

artificiel commented Sep 21, 2023

using the constructors of ofParameter in .h is great. however it's easy to slip in an error:

    ofParameter<uint16_t> seed_   { "seed", 0, 0, 1000 };
    ofParameter<void>     reinit_ { "re-init engine" };
    ofParameter<bool>     color_  { "color" };

so did you spot that the 3rd parameter is set to "true", with no name?

this works as expected:

    ofParameter<bool> color_ { "color", false };

it's because the single-arg template passes the arg as the init value, and not name except for the void versions and somehow C++ considers a non-null char * as "true" (albeit with a warning if the implicit conversions are required which is not the default.

question for a template nerd: without changing the general rules (it's OK that by default a single-arg param is prioritized about the value) would it be possible to "catch" that the implicit conversion of char * value for a <bool> parameter should be prohibited so we get an error? like passing a single string to other types:

image
(implicit conversions activated; otherwise it silently compiles, and it may take a while to figure out why the entry in ofxPanel is an empty rectangle...)

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

Successfully merging a pull request may close this issue.

1 participant