// =====================================================================================================================
//  fennec, a free and open source game engine
//  Copyright © 2025 - 2026  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/>.
// =====================================================================================================================

#ifndef FENNEC_RTTI_DETAIL_THIS_T_H
#define FENNEC_RTTI_DETAIL_THIS_T_H

#include <fennec/lang/type_transforms.h>

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