Czytałem następujące pytania związane z:Dlaczego std :: result_of <int(int)> :: type valid?
i the page on std::result_of
at cppreference.com.
Wszystkie z nich wydają się wskazywać, że powinienem być w stanie używać:
std::result_of<int(int)>::type v1 = 10;
Jednak gdy próbowałem budowania następujący program za pomocą g ++ 4.9.2
#include <type_traits>
int foo()
{
return 0;
}
int main()
{
std::result_of<int(int)>::type v1 = 10; // LINE A
std::result_of<decltype(foo)>::type v2 = 20; // LINE B
return 0;
}
dostaję komunikaty o błędach dla "LINII A" i "LINII B". Komunikaty o błędach są:
socc.cc: In function ‘int main()’:
socc.cc:10:5: error: ‘type’ is not a member of ‘std::result_of<int(int)>’
std::result_of<int(int)>::type v1 = 10;
^
socc.cc:11:5: error: ‘type’ is not a member of ‘std::result_of<int()>’
std::result_of<decltype(foo)>::type v2 = 20;
^
Komenda kiedyś skompilować:
g++ -std=c++11 -Wall socc.cc -o socc
FWIW korzystając
typename std::result_of<int(int)>::type v1 = 10;
typename std::result_of<decltype(foo)>::type v2 = 20;
nie zrobić różnicę.
Wygląda na to, że nie rozumiem, jak należy używać result_of
.
Czy możesz wyjaśnić, dlaczego dostaję błędy kompilatora?
Masz na myśli 'result_of <(int (int)) (int)>'? –
Zwróć uwagę, że 'result_of' zmieniono z C++ 11 na C++ 14, czy możesz potwierdzić, że pytasz o wersję C++ 11? –
@KerrekSB, Nie, miałem na myśli 'result_of <(int(int))>'. To może być brakująca część mojego zrozumienia "wyniku". Czy mógłbyś to rozwinąć? –