- Refactored lang yet again, `fennec/lang` is now C++ language. `fennec/string` `fennec/filesystem` and `fennec/format` are now independent.
77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright © 2025 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
///
|
|
/// \file _this_t.h
|
|
/// \brief
|
|
///
|
|
///
|
|
/// \details
|
|
/// \author Medusa Slockbower
|
|
///
|
|
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
|
///
|
|
///
|
|
|
|
#ifndef FENNEC_RTTI_DETAIL_THIS_T_H
|
|
#define FENNEC_RTTI_DETAIL_THIS_T_H
|
|
#include <fennec/lang/type_transforms.h>
|
|
|
|
#define FENNEC_DEFINE_THIS_T \
|
|
private: \
|
|
struct _this_t_tag {}; \
|
|
constexpr auto _this_t_helper() -> decltype(fennec::detail::_this::writer<_this_t_tag, decltype(this)>{}, void()) {} \
|
|
public: \
|
|
using this_t = fennec::detail::_this::read<_this_t_tag>
|
|
|
|
namespace fennec::detail
|
|
{
|
|
|
|
// https://stackoverflow.com/a/70701479
|
|
|
|
#if FENNEC_COMPILER_GCC
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wnon-template-friend"
|
|
#endif
|
|
|
|
namespace _this {
|
|
template <typename T>
|
|
struct reader
|
|
{
|
|
friend auto _test(reader<T>);
|
|
};
|
|
|
|
template <typename T, typename U>
|
|
struct writer
|
|
{
|
|
friend auto _test(reader<T>){return U{};}
|
|
};
|
|
|
|
inline void _test() {}
|
|
|
|
template <typename T>
|
|
using read = remove_pointer_t<decltype(_test(reader<T>{}))>;
|
|
};
|
|
|
|
#if FENNEC_COMPILER_GCC
|
|
#pragma GCC diagnostic pop
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif // FENNEC_RTTI_DETAIL_THIS_T_H
|