⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 no_function.cpp

📁 An article on the implementation of a fast C++ delegate with many advanced features.
💻 CPP
字号:
// FD.Delegate library examples

// Copyright Douglas Gregor 2001-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

// Copyright (C) 2007 JaeWook Choi
// , modified from Boost.Signals no_function.cpp

#include <iostream>
#include <boost/signals/signal2.hpp>
#include <fd/delegate/delegate2.hpp>
#include <string>
#include <functional>

void print_sum(int x, int y)
{
  std::cout << "Sum = " << x+y << std::endl;
}

void print_product(int x, int y)
{
  std::cout << "Product = " << x*y << std::endl;
}

void print_quotient(float x, float y)
{
  std::cout << "Quotient = " << x/y << std::endl;
}

int main()
{
  typedef boost::signal2<void, int, int, boost::last_value<void>,
                         std::string, std::less<std::string>,
                         void (*)(int, int)> sig_type;

  sig_type sig;
  sig.connect(&print_sum);
  sig.connect(&print_product);

  sig(3, 5); // print sum and product of 3 and 5

  // should fail
  //   sig.connect(&print_quotient);

  typedef fd::delegate2<void, int, int> dg_type;

  dg_type dg;
  dg.add(&print_sum);
  dg.add(&print_product);

  dg(3, 5); // print sum and product of 3 and 5

  // should fail
  //   dg.add(fd::resolution<void (int, int)>::select( &print_quotient ));

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -