闂茬潃鏃犺亰鍐欑偣浠�涔�

//
// Created by LCBHSStudent on 2020/2/25.
//

#ifndef SLOT_SIGNAL_BASE_FUNCTION_H
#define SLOT_SIGNAL_BASE_FUNCTION_H

#include <cstdint>
#include <array>

//namespace van {

constexpr int FUNCID    = 0;
constexpr int FUNCADDR  = 1;

using Delegate_Key = std::array<uintptr_t, 2>;

// 前向聲明
template <typename RT> class Function;
// 爲了實現Function< returnType (paraType1, paraType2...)> 類的聲明
template <typename RT, typename... Args>
class Function<RT(Args...)> {
// 定義函數指針類型
	using funcP = RT(*)(void*, Args&&...);

	static inline Function
	bind(Delegate_Key const& delegate_key) {
		return {
			reinterpret_cast<void*>(delegate_key[FUNCID]),
			reinterpret_cast<funcP>(delegate_key[FUNCADDR])
		};
	}

public:
	Function() = default;
	void* const instance_pointer = nullptr;
	funcP const function_pointer = nullptr;

	template<auto fun_ptr>
	static inline Function bind() {

	}
	// 調用函數
	inline RT operator() (Args... args) {
		return
		(*function_pointer)    // 保留參數的左右值屬性
		    (instance_pointer, std::forward<Args>(args)...);
	}

	inline explicit operator Delegate_Key() const {
		return {
			reinterpret_cast<std::uintptr_t>(instance_pointer),
			reinterpret_cast<std::uintptr_t>(function_pointer)
		};
	}
};


//}

#endif //SLOT_SIGNAL_BASE_FUNCTION_H

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章