|
// 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 ));
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.