-
Notifications
You must be signed in to change notification settings - Fork 48
Fix ElementHandle::setAs.*Array methods #351
Conversation
34d9d14
to
469d9a0
Compare
Current coverage is
|
{ | ||
return values.size(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using SFINAL to test for size() method existence
/** @return 0 by default, ie for non overloaded types. */
size_t getUserInputSize(...) { return 0; }
/** @return collection size if it has a size() method. does not participate to overload otherwise. */
template <class T, class..., class = decltype(&T::size)>
size_t getUserInputSize(T collection) { return collection.size(); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is worth it: It works but only if I add an overload for std::string (it has a size method but we don't want to consider it as a collection). I can't guarantee, ahead of time, that no future "scalar" type will have a size() method. We would rely too much on future tests begin correctly written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, then this should work:
template <class T>
size_t getUserInputSize(const T&) { return 0; }
template <class T>
size_t getUserInputSize(const std::vector<T> &t) { return t.size(); }
Direct accesses to array parameters were incorrectly identified, resulting in an error when the client tried to set them. This was caused by a programming mistake in using overloaded methods because `T`, `const T`, `T &` and `const T&` are different. Signed-off-by: David Wagner <[email protected]>
469d9a0
to
04b3a54
Compare
👍 |
Fix ElementHandle::setAs.*Array methods
Direct accesses to array parameters were incorrectly identified, resulting in
an error when the client tried to set them. This was caused by a programming
mistake in using overloaded methods because
T
,const T
,T &
andconst T&
are different. This is fixed by using the SFINAE principle and correctlyhanding all the cases described above.
79.54%