From 87207a8091892f5cd128ac19598ec2d3bf962851 Mon Sep 17 00:00:00 2001 From: Eric Cornelius Date: Wed, 25 Feb 2015 10:56:11 -0500 Subject: [PATCH] Support both move and reference overloads for the loop handler --- include/tins/internals.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/tins/internals.h b/include/tins/internals.h index 25debb9..e408f35 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -220,14 +220,19 @@ struct accepts_type()(std::declval

()) ), bool>::value >> : std::true_type { }; -// use enable_if to invoke the Packet& version of the sniff_loop handler if possible - otherwise fail to old behavior +// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior template bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value, bool>::type* = 0) { return f(std::move(p)); } template -bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value, bool>::type* = 0) { +bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value && accepts_type::value, bool>::type* = 0) { + return f(p); +} + +template +bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if::value && !accepts_type::value, bool>::type* = 0) { return f(*p.pdu()); } #endif