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

Assert template type for invalid setters #80

Merged
merged 2 commits into from
Nov 14, 2017

Conversation

magehrig
Copy link
Contributor

Ensure at compile time that template parameters conform to our assumptions.

nabo/nabo.h Outdated
@@ -217,11 +217,13 @@ namespace Nabo
// TODO (c++14) Convert invalidIndex, invalidValue to constexpr templated variables.
template <typename IndexType>
inline constexpr IndexType invalidIndex() {
static_assert(std::numeric_limits<IndexType>::is_integer, "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I'd suggest std::is_integral instead. That is a bit more symmetric and numeric_limits is not defined for non numeric types. The error might differ for some compilers between a false value and a substitution failure. I don't know what the standard says here. Does somebody else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the C++11 standard section 18.3.2.3: The default numeric_limits template shall have all members, but with 0 or false values. Still, I will change it to std::is_integral.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! I believed otherwise. Thanks for changing anyways.

@magehrig magehrig merged commit f96a292 into master Nov 14, 2017
@magehrig magehrig deleted the feature/invalid-type-assertion branch November 14, 2017 11:33
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 this pull request may close these issues.

2 participants