diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h index c2bfb38..23aebf8 100644 --- a/include/tins/detail/type_traits.h +++ b/include/tins/detail/type_traits.h @@ -31,6 +31,10 @@ #define TINS_TYPE_TRAITS_H #include +#include "cxxstd.h" +#if TINS_IS_CXX11 + #include +#endif namespace Tins { namespace Internals { @@ -73,6 +77,40 @@ struct is_unsigned_integral { static const bool value = true; }; +#if TINS_IS_CXX11 && !defined(_MSC_VER) + +// Template metaprogramming trait to determine if a functor can accept another parameter as an argument +template +struct accepts_type : std::false_type { }; + +template +struct accepts_type()(std::declval

()) ), bool>::value + >::type +> : std::true_type { }; + +// 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 && 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 + /** * \endcond */ diff --git a/include/tins/internals.h b/include/tins/internals.h index a4304e5..38c75ca 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -30,9 +30,6 @@ #ifndef TINS_INTERNALS_H #define TINS_INTERNALS_H -#if TINS_IS_CXX11 -#include -#endif #include #include #include "constants.h" @@ -190,36 +187,6 @@ inline bool is_dot3(const uint8_t* ptr, size_t sz) { return (sz >= 13 && ptr[12] < 8); } -#if TINS_IS_CXX11 && !defined(_MSC_VER) - -// Template metaprogramming trait to determine if a functor can accept another parameter as an argument -template -struct accepts_type : std::false_type { }; - -template -struct accepts_type()(std::declval

()) ), bool>::value - >::type -> : std::true_type { }; - -// 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 && 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 - } // namespace Internals } // namespace Tins /** diff --git a/include/tins/sniffer.h b/include/tins/sniffer.h index a3c7144..2cd2ec0 100644 --- a/include/tins/sniffer.h +++ b/include/tins/sniffer.h @@ -40,7 +40,7 @@ #include "cxxstd.h" #include "macros.h" #include "exceptions.h" -#include "internals.h" +#include "detail/type_traits.h" #ifdef TINS_HAVE_PCAP diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 68bbe44..2b95872 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -45,6 +45,7 @@ #include "pktap.h" #include "sll.h" #include "ppi.h" +#include "internals.h" using std::string; using std::runtime_error;