Bug 1484306 Part 4 - Use FunctionTypeTraits to yield better error message if aPredicate's signature is wrong. r=gerald

Differential Revision: https://phabricator.services.mozilla.com/D3684
This commit is contained in:
Ting-Yu Lin 2018-08-17 17:02:58 -07:00
parent 4e52c71be9
commit f90c2a2950
2 changed files with 17 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <stdio.h> /* for FILE* */
#include "nsDebug.h"
#include "nsTArray.h"
#include "mozilla/FunctionTypeTraits.h"
#include "mozilla/RefPtr.h"
#include "mozilla/ReverseIterator.h"
@ -241,6 +242,14 @@ public:
*/
template<typename Predicate>
nsFrameList Split(Predicate&& aPredicate) {
static_assert(
std::is_same<typename mozilla::FunctionTypeTraits<Predicate>::ReturnType,
bool>::value &&
mozilla::FunctionTypeTraits<Predicate>::arity == 1 &&
std::is_same<typename mozilla::FunctionTypeTraits<Predicate>::template ParameterType<0>,
nsIFrame*>::value,
"aPredicate should be of this function signature: bool(nsIFrame*)");
FrameLinkEnumerator link(*this);
link.Find(aPredicate);
return ExtractHead(link);

View File

@ -4777,6 +4777,14 @@ template<typename Predicate>
inline void
nsFrameList::FrameLinkEnumerator::Find(Predicate&& aPredicate)
{
static_assert(
std::is_same<typename mozilla::FunctionTypeTraits<Predicate>::ReturnType,
bool>::value &&
mozilla::FunctionTypeTraits<Predicate>::arity == 1 &&
std::is_same<typename mozilla::FunctionTypeTraits<Predicate>::template ParameterType<0>,
nsIFrame*>::value,
"aPredicate should be of this function signature: bool(nsIFrame*)");
for (; !AtEnd(); Next()) {
if (aPredicate(mFrame)) {
return;