forked from premiere/premiere-libtorrent
add static_asserts to alert_cast (#881)
This commit is contained in:
parent
75dca7116f
commit
34a2a7f7d4
|
@ -37,16 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <type_traits>
|
||||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
|
||||||
|
|
||||||
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
|
|
||||||
#include <boost/preprocessor/repetition/enum.hpp>
|
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
|
||||||
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
|
||||||
#include <boost/preprocessor/repetition/enum_shifted_binary_params.hpp>
|
|
||||||
|
|
||||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
|
||||||
|
|
||||||
// OVERVIEW
|
// OVERVIEW
|
||||||
//
|
//
|
||||||
|
@ -295,12 +286,17 @@ namespace libtorrent {
|
||||||
// ``alert_cast<>`` can only cast to an exact alert type, not a base class
|
// ``alert_cast<>`` can only cast to an exact alert type, not a base class
|
||||||
template <class T> T* alert_cast(alert* a)
|
template <class T> T* alert_cast(alert* a)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_base_of<alert, T>::value
|
||||||
|
, "alert_cast<> can only be used with alert types (deriving from libtorrent::alert)");
|
||||||
|
|
||||||
if (a == nullptr) return nullptr;
|
if (a == nullptr) return nullptr;
|
||||||
if (a->type() == T::alert_type) return static_cast<T*>(a);
|
if (a->type() == T::alert_type) return static_cast<T*>(a);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
template <class T> T const* alert_cast(alert const* a)
|
template <class T> T const* alert_cast(alert const* a)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_base_of<alert, T>::value
|
||||||
|
, "alert_cast<> can only be used with alert types (deriving from libtorrent::alert)");
|
||||||
if (a == nullptr) return nullptr;
|
if (a == nullptr) return nullptr;
|
||||||
if (a->type() == T::alert_type) return static_cast<T const*>(a);
|
if (a->type() == T::alert_type) return static_cast<T const*>(a);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue