Код: Выделить всё
#include
#include
struct testStruct {
double testMethod(int, float)
{
return {};
}
};
template
struct function_properties;
template
struct function_properties {
using return_type = R;
template
struct parameter {
using type = std::tuple_element::type;
};
};
void testFunction(auto method_ptr, auto& structObj) {
typename function_properties::return_type var_0{}; // Properly deduces double.
typename function_properties::parameter::type var_1{}; // Fails to deduce int.
if constexpr (std::is_same_v) // Fails to evaluate at compile time; "is not a valid template type argument for parameter"
{
}
auto memFn = std::mem_fn(method_ptr);
if constexpr (std::is_same_v) // Properly evaluated at compile time.
{
}
}
int main()
{
testStruct structObj;
auto method_ptr = &testStruct::testMethod;
typename function_properties::return_type var_0{}; // Properly deduces double.
typename function_properties::parameter::type var_1{}; // Properly deduces int.
if constexpr (std::is_same_v) // Properly evaluated at compile time.
{
}
testFunction(method_ptr, structObj);
return 0;
}
< /code>
Как видите, код в основной функции работает, как и ожидалось, но в функции, а не. Заинтересован в том, что std :: mem_fn Подробнее здесь: https://stackoverflow.com/questions/797 ... od-pointer
Мобильная версия