jeudi 23 mars 2023

How to understand the return type of `std::bind`?

A simple code snippet

#include <cstdio>
#include <functional>

int main() {
    auto f = std::bind(printf, "%d", std::placeholders::_2);
}

transforms to

#include <cstdio>
#include <functional>

int main()
{
  std::_Bind<int (*(const char *, std::_Placeholder<2>))(const char *, ...)> f = std::bind(printf, "%d", std::placeholders::_2);
  return 0;
}

using cppinsights.io (See https://cppinsights.io/s/71938cf6)

How to understand the int (*(const char *, std::_Placeholder<2>))(const char *, ...) part of return type std::_Bind<int (*(const char *, std::_Placeholder<2>))(const char *, ...)>?

I know that int (*)(const char *, ...) is a function pointer type, but what's the meaning of (*(const char *, std::_Placeholder<2>))? Is there any link to further understand this type?

Aucun commentaire:

Enregistrer un commentaire