Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created June 25, 2011 15:34
Show Gist options
  • Save shomah4a/1046594 to your computer and use it in GitHub Desktop.
Save shomah4a/1046594 to your computer and use it in GitHub Desktop.
const つけた
#include <iostream>
#include <boost/function.hpp>
class Test
{
public:
explicit Test(const int x): v(x)
{}
int add(const int x) const
{
return this->v + x;
}
int operator ()(const int x, const int y) const
{
return this->v + x + y;
}
private:
const int v;
};
int add(const int x, const int y)
{
return x + y;
}
int main(const int argc, const char* const args[])
{
const auto x = boost::function<int(const int, const int)>(add);
const auto y = boost::function<int(const Test&, const int)>(&Test::add);
const auto z = boost::function<int(const int, const int)>(Test(10));
std::cout << sizeof(x) << std::endl;
std::cout << sizeof(y) << std::endl;
std::cout << sizeof(z) << std::endl;
std::cout << x(10, 20) << std::endl;
std::cout << y(Test(10), 20) << std::endl;
std::cout << z(10, 20) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment