2012-02-15 01:11:29 +00:00
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=US-ASCII" >
< title > Chapter  1.  Boost.Functional/OverloadedFunction 1.0.0< / title >
< link rel = "stylesheet" href = "../../../../../doc/src/boostbook.css" type = "text/css" >
< meta name = "generator" content = "DocBook XSL Stylesheets V1.76.1" >
< link rel = "home" href = "index.html" title = "Chapter 1. Boost.Functional/OverloadedFunction 1.0.0" >
< link rel = "next" href = "boost_functional_overloadedfunction/Getting_Started.html" title = "Getting Started" >
< / head >
< body bgcolor = "white" text = "black" link = "#0000FF" vlink = "#840084" alink = "#0000FF" >
< table cellpadding = "2" width = "100%" > < tr >
< td valign = "top" > < img alt = "Boost C++ Libraries" width = "277" height = "86" src = "../../../../../boost.png" > < / td >
< td align = "center" > < a href = "../../../../../index.html" > Home< / a > < / td >
< td align = "center" > < a href = "../../../../../libs/libraries.htm" > Libraries< / a > < / td >
< td align = "center" > < a href = "http://www.boost.org/users/people.html" > People< / a > < / td >
< td align = "center" > < a href = "http://www.boost.org/users/faq.html" > FAQ< / a > < / td >
< td align = "center" > < a href = "../../../../../more/index.htm" > More< / a > < / td >
< / tr > < / table >
< hr >
< div class = "spirit-nav" > < a accesskey = "n" href = "boost_functional_overloadedfunction/Getting_Started.html" > < img src = "../../../../../doc/src/images/next.png" alt = "Next" > < / a > < / div >
< div class = "chapter" >
< div class = "titlepage" > < div >
< div > < h2 class = "title" >
< a name = "boost_functional_overloadedfunction" > < / a > Chapter  1.  Boost.Functional/OverloadedFunction 1.0.0< / h2 > < / div >
< div > < div class = "author" > < h3 class = "author" >
< span class = "firstname" > Lorenzo< / span > < span class = "surname" > Caminiti < code class = "email" > < < a class = "email" href = "mailto:lorcaminiti@gmail.com" > lorcaminiti@gmail.com< / a > > < / code > < / span >
< / h3 > < / div > < / div >
< div > < p class = "copyright" > Copyright © 2011, 2012 Lorenzo Caminiti< / p > < / div >
< div > < div class = "legalnotice" >
< a name = "boost_functional_overloadedfunction.legal" > < / a > < p >
Distributed under the Boost Software License, Version 1.0 (see accompanying
file LICENSE_1_0.txt or copy at < a href = "http://www.boost.org/LICENSE_1_0.txt" target = "_top" > http://www.boost.org/LICENSE_1_0.txt< / a > )
< / p >
< / div > < / div >
< / div > < / div >
< div class = "toc" >
< p > < b > Table of Contents< / b > < / p >
< dl >
< dt > < span class = "section" > < a href = "index.html#boost_functional_overloadedfunction.Introduction" > Introduction< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Getting_Started.html" > Getting
Started< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Getting_Started.html#boost_functional_overloadedfunction.Getting_Started.compilers_and_platforms" > Compilers
and Platforms< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Getting_Started.html#boost_functional_overloadedfunction.Getting_Started.installation" > Installation< / a > < / span > < / dt >
< / dl > < / dd >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Tutorial.html" > Tutorial< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Tutorial.html#boost_functional_overloadedfunction.Tutorial.overloading" > Overloading< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Tutorial.html#boost_functional_overloadedfunction.Tutorial.without_function_types" > Without
Function Types< / a > < / span > < / dt >
< / dl > < / dd >
< dt > < span class = "section" > < a href = "reference.html" > Reference< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "reference.html#header.boost.functional.overloaded_function_hpp" > Header < boost/functional/overloaded_function.hpp> < / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "reference.html#header.boost.functional.overloaded_function.config_hpp" > Header < boost/functional/overloaded_function/config.hpp> < / a > < / span > < / dt >
< / dl > < / dd >
< dt > < span class = "section" > < a href = "boost_functional_overloadedfunction/Acknowledgments.html" > Acknowledgments< / a > < / span > < / dt >
< / dl >
< / div >
< p >
This library allows to overload different functions into a single function object.
< / p >
< div class = "section boost_functional_overloadedfunction_Introduction" >
< div class = "titlepage" > < div > < div > < h2 class = "title" style = "clear: both" >
< a name = "boost_functional_overloadedfunction.Introduction" > < / a > < a class = "link" href = "index.html#boost_functional_overloadedfunction.Introduction" title = "Introduction" > Introduction< / a >
< / h2 > < / div > < / div > < / div >
< p >
Consider the following functions with distinct signatures:
< / p >
< p >
2012-03-22 20:54:20 +00:00
[identity_decls]
2012-02-15 01:11:29 +00:00
< / p >
< p >
Instead of calling them using their separate names (here < code class = "computeroutput" > < span class = "identifier" > BOOST_CHECK< / span > < / code >
is equivalent to < code class = "computeroutput" > < span class = "identifier" > assert< / span > < / code > ):
< sup > [< a name = "boost_functional_overloadedfunction.Introduction.f0" href = "#ftn.boost_functional_overloadedfunction.Introduction.f0" class = "footnote" > 1< / a > ]< / sup >
< / p >
< p >
< / p >
2012-02-20 20:11:42 +00:00
< pre class = "programlisting" > < span class = "identifier" > BOOST_CHECK< / span > < span class = "special" > (< / span > < span class = "identifier" > identity_s< / span > < span class = "special" > (< / span > < span class = "string" > "abc"< / span > < span class = "special" > )< / span > < span class = "special" > ==< / span > < span class = "string" > "abc"< / span > < span class = "special" > );< / span >
< span class = "identifier" > BOOST_CHECK< / span > < span class = "special" > (< / span > < span class = "identifier" > identity_i< / span > < span class = "special" > (< / span > < span class = "number" > 123< / span > < span class = "special" > )< / span > < span class = "special" > ==< / span > < span class = "number" > 123< / span > < span class = "special" > );< / span >
< span class = "identifier" > BOOST_CHECK< / span > < span class = "special" > (< / span > < span class = "identifier" > identity_d< / span > < span class = "special" > (< / span > < span class = "number" > 1.23< / span > < span class = "special" > )< / span > < span class = "special" > ==< / span > < span class = "number" > 1.23< / span > < span class = "special" > );< / span >
2012-02-15 01:11:29 +00:00
< / pre >
< p >
< / p >
< p >
It is possible to use this library to create a single < a href = "http://en.wikipedia.org/wiki/Function_overloading" target = "_top" > overloaded< / a >
function object (or < a href = "http://en.wikipedia.org/wiki/Functor" target = "_top" > functor< / a > )
named < code class = "computeroutput" > < span class = "identifier" > identity< / span > < / code > that aggregates
2012-03-22 20:54:20 +00:00
together the calls to the specific functions (see also < a href = "../../test/functor.cpp" target = "_top" > < code class = "literal" > functor.cpp< / code > < / a >
and < a href = "../../test/identity.hpp" target = "_top" > < code class = "literal" > identity.hpp< / code > < / a > ):
2012-02-15 01:11:29 +00:00
< / p >
< p >
< / p >
< pre class = "programlisting" > < span class = "identifier" > boost< / span > < span class = "special" > ::< / span > < span class = "identifier" > overloaded_function< / span > < span class = "special" > < < / span >
< span class = "keyword" > const< / span > < span class = "identifier" > std< / span > < span class = "special" > ::< / span > < span class = "identifier" > string< / span > < span class = "special" > & < / span > < span class = "special" > (< / span > < span class = "keyword" > const< / span > < span class = "identifier" > std< / span > < span class = "special" > ::< / span > < span class = "identifier" > string< / span > < span class = "special" > & )< / span >
< span class = "special" > ,< / span > < span class = "keyword" > int< / span > < span class = "special" > (< / span > < span class = "keyword" > int< / span > < span class = "special" > )< / span >
< span class = "special" > ,< / span > < span class = "keyword" > double< / span > < span class = "special" > (< / span > < span class = "keyword" > double< / span > < span class = "special" > )< / span >
< span class = "special" > > < / span > < span class = "identifier" > identity< / span > < span class = "special" > (< / span > < span class = "identifier" > identity_s< / span > < span class = "special" > ,< / span > < span class = "identifier" > identity_i< / span > < span class = "special" > ,< / span > < span class = "identifier" > identity_d< / span > < span class = "special" > );< / span >
< span class = "comment" > // All calls via single `identity` function.< / span >
2012-02-20 20:11:42 +00:00
< span class = "identifier" > BOOST_CHECK< / span > < span class = "special" > (< / span > < span class = "identifier" > identity< / span > < span class = "special" > (< / span > < span class = "string" > "abc"< / span > < span class = "special" > )< / span > < span class = "special" > ==< / span > < span class = "string" > "abc"< / span > < span class = "special" > );< / span >
< span class = "identifier" > BOOST_CHECK< / span > < span class = "special" > (< / span > < span class = "identifier" > identity< / span > < span class = "special" > (< / span > < span class = "number" > 123< / span > < span class = "special" > )< / span > < span class = "special" > ==< / span > < span class = "number" > 123< / span > < span class = "special" > );< / span >
< span class = "identifier" > BOOST_CHECK< / span > < span class = "special" > (< / span > < span class = "identifier" > identity< / span > < span class = "special" > (< / span > < span class = "number" > 1.23< / span > < span class = "special" > )< / span > < span class = "special" > ==< / span > < span class = "number" > 1.23< / span > < span class = "special" > );< / span >
2012-02-15 01:11:29 +00:00
< / pre >
< p >
< / p >
< p >
Note how the functions are called via a single overloaded function object
< code class = "computeroutput" > < span class = "identifier" > identity< / span > < / code > instead of using their
different names < code class = "computeroutput" > < span class = "identifier" > identity_s< / span > < / code > ,
< code class = "computeroutput" > < span class = "identifier" > identity_i< / span > < / code > , and < code class = "computeroutput" > < span class = "identifier" > identity_d< / span > < / code > .
< / p >
< / div >
< div class = "footnotes" >
< br > < hr width = "100" align = "left" >
< div class = "footnote" > < p > < sup > [< a id = "ftn.boost_functional_overloadedfunction.Introduction.f0" href = "#boost_functional_overloadedfunction.Introduction.f0" class = "para" > 1< / a > ] < / sup >
In the examples presented in this documentation, < code class = "computeroutput" > < span class = "identifier" > BOOST_CHECK< / span > < / code >
is used instead of < code class = "computeroutput" > < span class = "identifier" > assert< / span > < / code >
because it allows to write regression tests using < a href = "http://www.boost.org/libs/test" target = "_top" > Boost.Test< / a > .
The examples of this documentation are executed as part of the library test
suite to verify that they always compile and run correctly.
< / p > < / div >
< / div >
< / div >
< table xmlns:rev = "http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width = "100%" > < tr >
2012-03-22 20:54:20 +00:00
< td align = "left" > < p > < small > Last revised: March 22, 2012 at 20:51:03 GMT< / small > < / p > < / td >
2012-02-15 01:11:29 +00:00
< td align = "right" > < div class = "copyright-footer" > < / div > < / td >
< / tr > < / table >
< hr >
< div class = "spirit-nav" > < a accesskey = "n" href = "boost_functional_overloadedfunction/Getting_Started.html" > < img src = "../../../../../doc/src/images/next.png" alt = "Next" > < / a > < / div >
< / body >
< / html >