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

Constexpr DateTime/TimeSpan constructors #223

Open
maxbla opened this issue Mar 10, 2021 · 2 comments
Open

Constexpr DateTime/TimeSpan constructors #223

maxbla opened this issue Mar 10, 2021 · 2 comments

Comments

@maxbla
Copy link

maxbla commented Mar 10, 2021

  • Arduino board: All; N/a

  • Arduino IDE version (found in Arduino -> About Arduino menu): N/a

Feature Request: constexpr constructors for DateTime / TimeSpan

This would allow me to generate helpful error messages at compile time for DateTimes/TimeSpans that are invalid in a certain context using static_assert. Previously I have used run-time checks with Serial.println, but this method only catches mistakes if developers are looking at their serial console.

I think this is as simple as marking the constructors constexpr, but I might be missing something

@maxbla
Copy link
Author

maxbla commented Mar 14, 2021

After some investigation, most TimeSpan constructors can be made constexpr, but most DateTime constructors can't without C++14 constexpr features (Arduino currently uses C++11 by default).

@maxbla
Copy link
Author

maxbla commented Mar 14, 2021

If Arduino ever makes C++14 the default, This stack overflow question has some code that might be worth borrowing from.

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

No branches or pull requests

1 participant