I read the std :: thread documentation on cppreference (not always 100% accurate, I know) and noticed the following definition of behavior std::threadwhen the f"data pointer" element (rather than the "function element pointer") was passed as the first argument ( )) and the object of the required class as its second argument ( t1after copying to the stream-local storage):
If N == 1 and f is a pointer to a data object of a class element, then it is accessed. The value of the object is ignored. The following code is effectively executed: t1. * f, if the type t1 is either T, or a reference to T, or a reference to a type obtained from T. (* t1). * f otherwise.
Now I do not plan to use std::threadthis way, but I am confused by this definition. Apparently, the only thing that happens is that the data element is accessed, and the value is ignored, which seems to have no observable side effects at all, that is (as far as I can tell), it may not be op. (Maybe I missed something obvious ...?)
At first I thought it could be a typo, and this means that the data member is accessed and then called (since it can be a called object, even if it is not a function), but I checked it with the following code in GCC-4.7 , and there really is no call:
#include <iostream>
#include <thread>
struct S
{
void f() {
std::cout << "Calling f()" << std::endl;
}
struct {
void operator()() {
std::cout << "Calling g()" << std::endl;
}
} g;
};
int main(int, char**)
{
S s;
s.f();
s.g();
std::cout << "----" << std::endl;
auto x = &S::f;
auto y = &S::g;
(s.*x)();
(s.*y)();
std::cout << "----" << std::endl;
std::thread t(x, &s);
t.join();
std::thread u(y, &s);
u.join();
return 0;
}
- , , , ? , ", ", "--" "---"? , , , " ---" "--" ( - SFINAE, ...?)
, , , , , - , ... - ?