std::tr1::_Bind<void (*()(std::tr1::reference_wrapper<int>))(int&)>
I understand std::tr1::reference_wrapper<int>
and this whole thing is some sort of function pointer that returns void
and takes int&
as argument. But I can't seem to follow the *() in the beginning. The code's cut-pasted from some gdb session i was going through a while back.
Also, what is the type to tr1::function? Some function which returns void and takes no argument?
0x00000001000021a1 in std::tr1::function<void ()()>::operator() (this=0x7fff5fbffb98) at functional_iterate.h:865
But then the following is an error:
template <typename T>
void f()
{
cout << "general\n";
}
template<>
void f<void ()()> () // this is error
{
cout << "specific\n";
}
There are three kinds of templates: function templates, class templates and, since C++14, variable templates. Since C++11, templates may be either variadic or non-variadic; in earlier versions of C++ they are always non-variadic.
There are two types of templates in C++, function templates and class templates.
A template is a form, mold or pattern used as a guide to make something. Here are some examples of templates: Website design. Creating a document. Knitting a sweater.
Templates are pre-formatted documents designed to create commonly used document types such as letters, fax forms, or envelopes.
This is an instance of std::tr1::_Bind
instantiated on the type of a function taking a std::tr1::reference_wrapper<int>
and returning a pointer to a function taking a reference to int and returning void.
Here's how to read it:
std::tr1::_Bind<
type>
should be clear.void (
fn)(int&)
is a function taking int&
and returning void
.*
ptr so it's actually a pointer to function(
fn2)(std::tr1::reference_wrapper<int>)
is a function taking std::tr1::reference_wrapper<int>
and what we had up to now is its return type.However as I now notice when the fn2 is empty, the parentheses around it should probably also not be there (similar to how you write the function type "function taking no parameters and returning void" as void()
, not void()()
.
The case in std::tr1::function
is exactly that one: A function taking no parameters and returning void
, with extra parentheses around the empty "function name".
OK, now tested it: gdb indeed outputs void()
as void()()
; this probably should be considered a gdb bug.
The correct way to write the first type in C++ therefore is:
std::tr1::_Bind<void (*(std::tr1::reference_wrapper<int>))(int&)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With