initial matador ng commit

This commit is contained in:
2025-02-02 20:37:12 +01:00
parent 19de5714f4
commit ded3daceb3
378 changed files with 14913 additions and 13431 deletions
+42
View File
@@ -0,0 +1,42 @@
#ifndef BASE_CLASS_HPP
#define BASE_CLASS_HPP
#include <type_traits>
namespace matador {
/**
* @brief Safely casts a given derived class to its base class
*
* @tparam B The base class type
* @tparam D The class type of the derived class
* @param derived The derived object
* @return The casted object
*/
template < class B, class D>
const B* base_class(const D *derived)
{
static_assert(!std::is_same_v<B, D>, "class B must not be of same type as class D");
static_assert(std::is_base_of_v<B, D>, "class B must be base of class D");
return static_cast<const B*>(derived);
}
/**
* @brief Safely casts a given derived class to its base class
*
* @tparam B The base class type
* @tparam D The class type of the derived class
* @param derived The derived object
* @return The casted object
*/
template < class B, class D>
B* base_class(D *derived)
{
static_assert(!std::is_same_v<B, D>, "class B must not be of same type as class D");
static_assert(std::is_base_of_v<B, D>, "class B must be base of class D");
return static_cast<B*>(derived);
}
}
#endif /* BASE_CLASS_HPP */