//********************************************************
// The following code example is taken from the book
//  C++23 - The Complete Guide
//  by Nicolai M. Josuttis (www.josuttis.com)
//  https://www.cppstd23.com
//
// The code is licensed under a
//  Creative Commons Attribution 4.0 International License
//  https://creativecommons.org/licenses/by/4.0/
//********************************************************


#include <iostream>
#include <functional>

int cube(int i) {
  return i * i * i;
}

void call(std::function<int(int)> f) {
  if (f) {
    std::cout << f(7) << '\n';
  }
}

int main()
{
  std::function<int(int)> func;
  call(func);

  func = cube;                          // refer to ordinary function
  call(func);

  func = std::negate<int>{};            // refer to function object
  call(func);

  func = [] (int i) { return i * i; };  // refer to lambda
  call(func);
}

