mirror of
https://github.com/boostorg/parameter.git
synced 2026-01-19 16:32:13 +00:00
Compare commits
148 Commits
svn-branch
...
boost-1.69
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d3e39325e | ||
|
|
058b1394f5 | ||
|
|
de183a3b75 | ||
|
|
28a8f75d83 | ||
|
|
2e9b937082 | ||
|
|
61d476d4b6 | ||
|
|
02a59d2091 | ||
|
|
007a24b76c | ||
|
|
672ae1c0ce | ||
|
|
f7829bd91c | ||
|
|
3736a0581e | ||
|
|
6f747e9869 | ||
|
|
b31fc2bb17 | ||
|
|
247536c841 | ||
|
|
fd4a18d490 | ||
|
|
a2da4c32f5 | ||
|
|
a3b5ce8a93 | ||
|
|
612563e0fe | ||
|
|
904e2f5020 | ||
|
|
c303922fe9 | ||
|
|
9a8ad86fd7 | ||
|
|
0461c0a070 | ||
|
|
6ad2d6b207 | ||
|
|
45eebd0b85 | ||
|
|
d6132a7645 | ||
|
|
3462c3dc06 | ||
|
|
bc19656218 | ||
|
|
09cc5cf219 | ||
|
|
dd466e7d54 | ||
|
|
368205ab37 | ||
|
|
9821c1a5f9 | ||
|
|
d3a422ba6e | ||
|
|
aaf00c5449 | ||
|
|
a9a4287f4d | ||
|
|
e1f43668e7 | ||
|
|
3b34198a6f | ||
|
|
49ab4faa2b | ||
|
|
54854d4a3a | ||
|
|
45295c87bc | ||
|
|
0dcd40da74 | ||
|
|
a510824ee4 | ||
|
|
7465ba08d3 | ||
|
|
8dca3b7307 | ||
|
|
51a02e0822 | ||
|
|
a07961f561 | ||
|
|
4e26b448e9 | ||
|
|
b5e57e0024 | ||
|
|
b74489d477 | ||
|
|
475001a591 | ||
|
|
f9e0d1c5c3 | ||
|
|
23ed477c44 | ||
|
|
6427d82103 | ||
|
|
436209fa82 | ||
|
|
9d66bd7632 | ||
|
|
0b0ce28a8a | ||
|
|
bdcbf442bf | ||
|
|
15d8701d77 | ||
|
|
c9cf0ab0f5 | ||
|
|
ee32bc6f67 | ||
|
|
20301b3da4 | ||
|
|
c2177b122c | ||
|
|
59e172adb3 | ||
|
|
359b3a5c3a | ||
|
|
522c1e33b0 | ||
|
|
9f4334c1c1 | ||
|
|
7ff5c4b996 | ||
|
|
298108e7ed | ||
|
|
1b1499b94c | ||
|
|
ae3bfbad46 | ||
|
|
d8a61e4df7 | ||
|
|
82b5cc0208 | ||
|
|
91623e6241 | ||
|
|
4af5c63d46 | ||
|
|
1c2f56c672 | ||
|
|
08b0a74035 | ||
|
|
4c8725641d | ||
|
|
b91cd816c8 | ||
|
|
3cf03f73ca | ||
|
|
f9a2fba9ab | ||
|
|
55792af45f | ||
|
|
04cea6497d | ||
|
|
e054a75533 | ||
|
|
834f245953 | ||
|
|
ef9dfeb2d1 | ||
|
|
e6eda9a776 | ||
|
|
98bcbbad78 | ||
|
|
d9f0e42397 | ||
|
|
0a26a05500 | ||
|
|
8a404e2d67 | ||
|
|
31f9f620fe | ||
|
|
2e725894c6 | ||
|
|
a4b2742095 | ||
|
|
2af6d0439e | ||
|
|
56ddeddfaf | ||
|
|
276d786ed9 | ||
|
|
fe43dad724 | ||
|
|
ce2d43c1b5 | ||
|
|
86d7201a99 | ||
|
|
ccf40a29c1 | ||
|
|
28ed7b9704 | ||
|
|
6c3ee189d1 | ||
|
|
15048a1d82 | ||
|
|
3852ff760c | ||
|
|
916b4d2c2f | ||
|
|
af9b04e7ad | ||
|
|
894dffe6ff | ||
|
|
c17ea8d26d | ||
|
|
1844c27699 | ||
|
|
9694b76bf2 | ||
|
|
7c9ddf23e0 | ||
|
|
224d313a05 | ||
|
|
47c53efbaa | ||
|
|
57ef2b6ee9 | ||
|
|
297e85c0f1 | ||
|
|
3a59d2cea3 | ||
|
|
58bb633dc0 | ||
|
|
3397bafb4a | ||
|
|
cc256f0bb3 | ||
|
|
e3b060b3e5 | ||
|
|
0791667e33 | ||
|
|
91ffd43483 | ||
|
|
fa751e022e | ||
|
|
1f6c9a3034 | ||
|
|
6c209395aa | ||
|
|
5231f04b27 | ||
|
|
c7258e9c9e | ||
|
|
22a1f905e9 | ||
|
|
0417a36693 | ||
|
|
d42b860b8d | ||
|
|
c5168be5d7 | ||
|
|
c29a75c9df | ||
|
|
e18d621508 | ||
|
|
40399d3505 | ||
|
|
d6db8c6216 | ||
|
|
38817a8bb5 | ||
|
|
646c519dc0 | ||
|
|
cb501f9f38 | ||
|
|
7eb7737095 | ||
|
|
bfc5811fdc | ||
|
|
1f8f44b26c | ||
|
|
6729c38504 | ||
|
|
cf5d2c46f5 | ||
|
|
49e928273d | ||
|
|
00bbfbb20c | ||
|
|
ca120a3f04 | ||
|
|
e2b452c1f4 | ||
|
|
6695f76c5f | ||
|
|
bf25a637c8 |
136
.travis.yml
Normal file
136
.travis.yml
Normal file
@@ -0,0 +1,136 @@
|
||||
# Copyright 2016 Edward Diener
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
python: "2.7"
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /feature\/.*/
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
|
||||
include:
|
||||
- os: linux
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.4
|
||||
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.4
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.6
|
||||
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-5
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-6
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libstdc++-5-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-libc++
|
||||
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libc++-dev
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
|
||||
install:
|
||||
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
||||
- cd ..
|
||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init tools/boostdep
|
||||
- git submodule update --init libs/parameter_python
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/parameter
|
||||
- python tools/boostdep/depinst/depinst.py parameter
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- |-
|
||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
||||
- ./b2 --verbose-test libs/config/test//config_info toolset=$TOOLSET cxxstd=$CXXSTD || true
|
||||
- ./b2 -j3 libs/parameter/test toolset=$TOOLSET cxxstd=$CXXSTD
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
||||
37
appveyor.yml
Normal file
37
appveyor.yml
Normal file
@@ -0,0 +1,37 @@
|
||||
# Copyright 2017 Edward Diener
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0,msvc-14.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init tools/boostdep
|
||||
- git submodule update --init libs/parameter_python
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\parameter
|
||||
- python tools/boostdep/depinst/depinst.py parameter
|
||||
- bootstrap
|
||||
- b2 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- b2 libs/parameter/test toolset=%TOOLSET%
|
||||
12
doc/Jamfile.v2
Executable file → Normal file
12
doc/Jamfile.v2
Executable file → Normal file
@@ -1,12 +1,12 @@
|
||||
# Copyright David Abrahams 2006. Distributed under 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)
|
||||
|
||||
import docutils ;
|
||||
|
||||
import path ;
|
||||
sources = [ path.glob . : *.rst ] ;
|
||||
sources = [ glob *.rst ] ;
|
||||
bases = $(sources:S=) ;
|
||||
|
||||
|
||||
# This is a path relative to the html/ subdirectory where the
|
||||
# generated output will eventually be moved.
|
||||
stylesheet = "--stylesheet=rst.css" ;
|
||||
@@ -22,3 +22,9 @@ for local b in $(bases)
|
||||
|
||||
alias htmls : $(bases) ;
|
||||
stage html : $(bases) ;
|
||||
|
||||
###############################################################################
|
||||
alias boostdoc ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease : html ;
|
||||
explicit boostrelease ;
|
||||
|
||||
17
doc/README.txt
Normal file
17
doc/README.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
.. -*-rst-*-
|
||||
|
||||
.. Copyright David Abrahams 2009. Distributed under 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)
|
||||
|
||||
To build the html::
|
||||
|
||||
bjam html
|
||||
|
||||
To test the code in this documentation:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
python ../../../tools/litre/tool.py `pwd`/index.rst --dump_dir=../test/literate
|
||||
cd ../test/literate
|
||||
bjam
|
||||
901
doc/html/index.html
Executable file → Normal file
901
doc/html/index.html
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,787 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<title>The Boost Parameter Library Python Binding Documentation</title>
|
||||
<meta name="authors" content="Daniel Wallin" />
|
||||
<meta name="organization" content="Boost Consulting" />
|
||||
<meta name="date" content="2006-12-14" />
|
||||
<meta name="copyright" content="Copyright David Abrahams, Daniel Wallin 2005. Distributed under 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)" />
|
||||
<link rel="stylesheet" href="rst.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="the-boost-parameter-library-python-binding-documentation">
|
||||
<h1 class="title">The Boost Parameter Library Python Binding Documentation</h1>
|
||||
<table class="docinfo" frame="void" rules="none">
|
||||
<col class="docinfo-name" />
|
||||
<col class="docinfo-content" />
|
||||
<tbody valign="top">
|
||||
<tr><th class="docinfo-name">Authors:</th>
|
||||
<td>Daniel Wallin</td></tr>
|
||||
<tr><th class="docinfo-name">Contact:</th>
|
||||
<td><a class="first last reference" href="mailto:dalwan01@student.umu.se">dalwan01@student.umu.se</a></td></tr>
|
||||
<tr><th class="docinfo-name">Organization:</th>
|
||||
<td><a class="first last reference" href="http://www.boost-consulting.com">Boost Consulting</a></td></tr>
|
||||
<tr><th class="docinfo-name">Date:</th>
|
||||
<td>2006-12-14</td></tr>
|
||||
<tr><th class="docinfo-name">Copyright:</th>
|
||||
<td>Copyright David Abrahams, Daniel Wallin
|
||||
2005. Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at <a class="reference" href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="abstract topic">
|
||||
<p class="topic-title first">Abstract</p>
|
||||
<p>Makes it possible to bind Boost.Parameter-enabled
|
||||
functions, operators and constructors to Python.</p>
|
||||
</div>
|
||||
<p><a class="reference" href="../../../../index.htm"><img alt="Boost" src="../../../../boost.png" /></a></p>
|
||||
<div class="contents topic">
|
||||
<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="#introduction" id="id7" name="id7">Introduction</a></li>
|
||||
<li><a class="reference" href="#tutorial" id="id8" name="id8">Tutorial</a></li>
|
||||
<li><a class="reference" href="#concept-parameterspec" id="id9" name="id9">concept <span class="concept">ParameterSpec</span></a></li>
|
||||
<li><a class="reference" href="#special-keywords" id="id10" name="id10"><em>special</em> keywords</a></li>
|
||||
<li><a class="reference" href="#class-template-init" id="id11" name="id11">class template <tt class="docutils literal"><span class="pre">init</span></tt></a></li>
|
||||
<li><a class="reference" href="#class-template-call" id="id12" name="id12">class template <tt class="docutils literal"><span class="pre">call</span></tt></a></li>
|
||||
<li><a class="reference" href="#class-template-function" id="id13" name="id13">class template <tt class="docutils literal"><span class="pre">function</span></tt></a></li>
|
||||
<li><a class="reference" href="#function-template-def" id="id14" name="id14">function template <tt class="docutils literal"><span class="pre">def</span></tt></a></li>
|
||||
<li><a class="reference" href="#portability" id="id15" name="id15">Portability</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id7" id="introduction" name="introduction">Introduction</a></h1>
|
||||
<p><tt class="docutils literal"><span class="pre">boost/parameter/python.hpp</span></tt> introduces a group of <a class="reference" href="../../../python/doc/v2/def_visitor.html"><tt class="docutils literal"><span class="pre">def_visitors</span></tt></a> that can
|
||||
be used to easily expose Boost.Parameter-enabled member functions to Python with
|
||||
Boost.Python. It also provides a function template <tt class="docutils literal"><span class="pre">def()</span></tt> that can be used
|
||||
to expose Boost.Parameter-enabled free functions.</p>
|
||||
<p>When binding a Boost.Parameter enabled function, the keyword tags
|
||||
must be specified. Additionally, because Boost.Parameter enabled
|
||||
functions are templates, the desired function signature must be
|
||||
specified.</p>
|
||||
<!-- The keyword tags are specified as an `MPL Sequence`_, using the
|
||||
pointer qualifications described in |ParameterSpec|_ below. The
|
||||
signature is also specifid as an `MPL sequence`_ of parameter
|
||||
types. Additionally, ``boost::parameter::python::function`` and
|
||||
``boost::parameter::python::def`` requires a class with forwarding
|
||||
overloads. We will take a closer look at how this is done in the
|
||||
tutorial section below. -->
|
||||
<p>The keyword tags and associated argument types are specified as an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL
|
||||
Sequence</a>, using the function type syntax described in <a class="reference" href="#concept-parameterspec"><span class="concept">ParameterSpec</span></a>
|
||||
below. Additionally, <tt class="docutils literal"><span class="pre">boost::parameter::python::function</span></tt> and
|
||||
<tt class="docutils literal"><span class="pre">boost::parameter::python::def</span></tt> requires a class with forwarding overloads.
|
||||
We will take a closer look at how this is done in the tutorial section below.</p>
|
||||
<!-- The last two sentences are terribly vague. Which namespace is -->
|
||||
<!-- ``function`` in? Isn't the return type always needed? What -->
|
||||
<!-- else are we going to do other than pass these sequences to -->
|
||||
<!-- function? -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id8" id="tutorial" name="tutorial">Tutorial</a></h1>
|
||||
<p>In this section we will outline the steps needed to bind a simple
|
||||
Boost.Parameter-enabled member function to Python. Knowledge of the
|
||||
Boost.Parameter <a class="reference" href="index.html">macros</a> are required to understand this section.</p>
|
||||
<p>The class and member function we are interested in binding looks
|
||||
like this:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
|
||||
// First the keywords
|
||||
BOOST_PARAMETER_KEYWORD(tag, title)
|
||||
BOOST_PARAMETER_KEYWORD(tag, width)
|
||||
BOOST_PARAMETER_KEYWORD(tag, height)
|
||||
|
||||
class window
|
||||
{
|
||||
public:
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION(
|
||||
(void), open, tag,
|
||||
(required (title, (std::string)))
|
||||
(optional (width, (unsigned), 400)
|
||||
(height, (unsigned), 400))
|
||||
)
|
||||
{
|
||||
<em>… function implementation …</em>
|
||||
}
|
||||
};
|
||||
</pre>
|
||||
<!-- @example.prepend('#include <cassert>') -->
|
||||
<!-- @example.replace_emphasis('''
|
||||
assert(title == "foo");
|
||||
assert(height == 20);
|
||||
assert(width == 400);
|
||||
''') -->
|
||||
<p>It defines a set of overloaded member functions called <tt class="docutils literal"><span class="pre">open</span></tt> with one
|
||||
required parameter and two optional ones. To bind this member function to
|
||||
Python we use the binding utility <tt class="docutils literal"><span class="pre">boost::parameter::python::function</span></tt>.
|
||||
<tt class="docutils literal"><span class="pre">boost::parameter::python::function</span></tt> is a <a class="reference" href="../../../python/doc/v2/def_visitor.html"><tt class="docutils literal"><span class="pre">def_visitor</span></tt></a> that we'll instantiate
|
||||
and pass to <tt class="docutils literal"><span class="pre">boost::python::class_::def()</span></tt>.</p>
|
||||
<p>To use <tt class="docutils literal"><span class="pre">boost::parameter::python::function</span></tt> we first need to define
|
||||
a class with forwarding overloads. This is needed because <tt class="docutils literal"><span class="pre">window::open()</span></tt>
|
||||
is a function template, so we can't refer to it in any other way.</p>
|
||||
<pre class="literal-block">
|
||||
struct open_fwd
|
||||
{
|
||||
template <class A0, class A1, class A2>
|
||||
void operator()(
|
||||
boost::type<void>, window& self
|
||||
, A0 const& a0, A1 const& a1, A2 const& a2
|
||||
)
|
||||
{
|
||||
self.open(a0, a1, a2);
|
||||
}
|
||||
};
|
||||
</pre>
|
||||
<p>The first parameter, <tt class="docutils literal"><span class="pre">boost::type<void></span></tt>, tells the forwarding overload
|
||||
what the return type should be. In this case we know that it's always void
|
||||
but in some cases, when we are exporting several specializations of a
|
||||
Boost.Parameter-enabled template, we need to use that parameter to
|
||||
deduce the return type.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">window::open()</span></tt> takes a total of 3 parameters, so the forwarding function
|
||||
needs to take three parameters as well.</p>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">We only need one overload in the forwarding class, despite the
|
||||
fact that there are two optional parameters. There are special
|
||||
circumstances when several overload are needed; see
|
||||
<a class="reference" href="#special-keywords">special keywords</a>.</p>
|
||||
</div>
|
||||
<p>Next we'll define the module and export the class:</p>
|
||||
<pre class="literal-block">
|
||||
BOOST_PYTHON_MODULE(my_module)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = boost::parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<window>("window")
|
||||
.def(
|
||||
"open", py::function<
|
||||
open_fwd
|
||||
, mpl::vector<
|
||||
void
|
||||
, tag::title(std::string)
|
||||
, tag::width*(unsigned)
|
||||
, tag::height*(unsigned)
|
||||
>
|
||||
>()
|
||||
);
|
||||
}
|
||||
</pre>
|
||||
<!-- @jam_prefix.append('import python ;') -->
|
||||
<!-- @jam_prefix.append('stage . : my_module /boost/python//boost_python ;') -->
|
||||
<!-- @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
, howmany = 'all'
|
||||
) -->
|
||||
<!-- @del jam_prefix[:] -->
|
||||
<p><tt class="docutils literal"><span class="pre">py::function</span></tt> is passed two parameters. The first one is the class with
|
||||
forwarding overloads that we defined earlier. The second one is an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL
|
||||
Sequence</a> with the keyword tag types and argument types for the function
|
||||
specified as function types. The pointer syntax used in <tt class="docutils literal"><span class="pre">tag::width*</span></tt> and
|
||||
<tt class="docutils literal"><span class="pre">tag::height*</span></tt> means that the parameter is optional. The first element of
|
||||
the <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL Sequence</a> is the return type of the function, in this case <tt class="docutils literal"><span class="pre">void</span></tt>,
|
||||
which is passed as the first argument to <tt class="docutils literal"><span class="pre">operator()</span></tt> in the forwarding
|
||||
class.</p>
|
||||
<!-- The
|
||||
pointer syntax means that the parameter is optional, so in this case
|
||||
``width`` and ``height`` are optional parameters. The third parameter
|
||||
is an `MPL Sequence`_ with the desired function signature. The return type comes first, and
|
||||
then the parameter types:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
mpl::vector<void, std::string, unsigned, unsigned>
|
||||
*return type* *title* *width* *height*
|
||||
|
||||
.. @ignore() -->
|
||||
<p>That's it! This class can now be used in Python with the expected syntax:</p>
|
||||
<pre class="literal-block">
|
||||
>>> w = my_module.window()
|
||||
>>> w.open(title = "foo", height = 20)
|
||||
</pre>
|
||||
<!-- @example.prepend('import my_module') -->
|
||||
<!-- @run_python(module_path = my_module) -->
|
||||
<!-- Sorry to say this at such a late date, but this syntax really -->
|
||||
<!-- strikes me as cumbersome. Couldn't we do something like:
|
||||
|
||||
class_<window>("window")
|
||||
.def(
|
||||
"open",
|
||||
(void (*)(
|
||||
tag::title(std::string),
|
||||
tag::width*(unsigned),
|
||||
tag::height*(unsigned))
|
||||
)0
|
||||
);
|
||||
|
||||
or at least:
|
||||
|
||||
class_<window>("window")
|
||||
.def(
|
||||
"open",
|
||||
mpl::vector<
|
||||
void,
|
||||
tag::title(std::string),
|
||||
tag::width*(unsigned),
|
||||
tag::height*(unsigned)
|
||||
>()
|
||||
);
|
||||
|
||||
assuming, that is, that we will have to repeat the tags (yes,
|
||||
users of broken compilers will have to give us function pointer
|
||||
types instead). -->
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id9" id="concept-parameterspec" name="concept-parameterspec">concept <span class="concept">ParameterSpec</span></a></h1>
|
||||
<p>A <span class="concept">ParameterSpec</span> is a function type <tt class="docutils literal"><span class="pre">K(T)</span></tt> that describes both the keyword tag,
|
||||
<tt class="docutils literal"><span class="pre">K</span></tt>, and the argument type, <tt class="docutils literal"><span class="pre">T</span></tt>, for a parameter.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">K</span></tt> is either:</p>
|
||||
<ul class="simple">
|
||||
<li>A <em>required</em> keyword of the form <tt class="docutils literal"><span class="pre">Tag</span></tt></li>
|
||||
<li><strong>or</strong>, an <em>optional</em> keyword of the form <tt class="docutils literal"><span class="pre">Tag*</span></tt></li>
|
||||
<li><strong>or</strong>, a <em>special</em> keyword of the form <tt class="docutils literal"><span class="pre">Tag**</span></tt></li>
|
||||
</ul>
|
||||
<p>where <tt class="docutils literal"><span class="pre">Tag</span></tt> is a keyword tag type, as used in a specialization
|
||||
of <a class="reference" href="../../../parameter/doc/html/reference.html#keyword"><tt class="docutils literal"><span class="pre">boost::parameter::keyword</span></tt></a>.</p>
|
||||
<p>The <strong>arity range</strong> for an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL Sequence</a> of <span class="concept">ParameterSpec</span>'s is
|
||||
defined as the closed range:</p>
|
||||
<pre class="literal-block">
|
||||
[ mpl::size<S> - number of <em>special</em> keyword tags in <tt class="docutils literal"><span class="pre">S</span></tt>, mpl::size<S> ]
|
||||
</pre>
|
||||
<p>For example, the <strong>arity range</strong> of <tt class="docutils literal"><span class="pre">mpl::vector2<x(int),y(int)></span></tt> is <tt class="docutils literal"><span class="pre">[2,2]</span></tt>,
|
||||
the <strong>arity range</strong> of <tt class="docutils literal"><span class="pre">mpl::vector2<x(int),y*(int)></span></tt> is <tt class="docutils literal"><span class="pre">[2,2]</span></tt> and the
|
||||
<strong>arity range</strong> of <tt class="docutils literal"><span class="pre">mpl::vector2<x(int),y**(int)></span></tt> is <tt class="docutils literal"><span class="pre">[1,2]</span></tt>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id10" id="special-keywords" name="special-keywords"><em>special</em> keywords</a></h1>
|
||||
<p>Sometimes it is desirable to have a default value for a parameter that differ
|
||||
in type from the parameter. This technique is useful for doing simple tag-dispatching
|
||||
based on the presence of a parameter. For example:</p>
|
||||
<!-- An example_ of this is given in the Boost.Parameter
|
||||
docs. The example uses a different technique, but could also have been written like this: -->
|
||||
<pre class="literal-block">
|
||||
namespace core
|
||||
{
|
||||
template <class ArgumentPack>
|
||||
void dfs_dispatch(ArgumentPack const& args, mpl::false_)
|
||||
{
|
||||
<em>…compute and use default color map…</em>
|
||||
}
|
||||
|
||||
template <class ArgumentPack, class ColorMap>
|
||||
void dfs_dispatch(ArgumentPack const& args, ColorMap colormap)
|
||||
{
|
||||
<em>…use colormap…</em>
|
||||
}
|
||||
}
|
||||
|
||||
template <class ArgumentPack>
|
||||
void depth_first_search(ArgumentPack const& args)
|
||||
{
|
||||
core::dfs_dispatch(args, args[color | mpl::false_()]);
|
||||
}
|
||||
</pre>
|
||||
<!-- @example.prepend('''
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/parameters.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <cassert>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, color);
|
||||
|
||||
typedef boost::parameter::parameters<tag::color> params;
|
||||
|
||||
namespace mpl = boost::mpl;
|
||||
''') -->
|
||||
<!-- @example.replace_emphasis('''
|
||||
assert(args[color | 1] == 1);
|
||||
''') -->
|
||||
<!-- @example.replace_emphasis('''
|
||||
assert(args[color | 1] == 0);
|
||||
''') -->
|
||||
<!-- @example.append('''
|
||||
int main()
|
||||
{
|
||||
depth_first_search(params()());
|
||||
depth_first_search(params()(color = 0));
|
||||
}''') -->
|
||||
<!-- @build() -->
|
||||
<!-- .. _example: index.html#dispatching-based-on-the-presence-of-a-default -->
|
||||
<p>In the above example the type of the default for <tt class="docutils literal"><span class="pre">color</span></tt> is <tt class="docutils literal"><span class="pre">mpl::false_</span></tt>, a
|
||||
type that is distinct from any color map that the user might supply.</p>
|
||||
<p>When binding the case outlined above, the default type for <tt class="docutils literal"><span class="pre">color</span></tt> will not
|
||||
be convertible to the parameter type. Therefore we need to tag the <tt class="docutils literal"><span class="pre">color</span></tt>
|
||||
keyword as a <em>special</em> keyword. This is done by specifying the tag as
|
||||
<tt class="docutils literal"><span class="pre">tag::color**</span></tt> when binding the function (see <a class="reference" href="#concept-parameterspec">concept ParameterSpec</a> for
|
||||
more details on the tagging). By doing this we tell the binding functions that
|
||||
it needs to generate two overloads, one with the <tt class="docutils literal"><span class="pre">color</span></tt> parameter present
|
||||
and one without. Had there been two <em>special</em> keywords, four overloads would
|
||||
need to be generated. The number of generated overloads is equal to 2<sup>N</sup>, where <tt class="docutils literal"><span class="pre">N</span></tt> is the number of <em>special</em> keywords.</p>
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id11" id="class-template-init" name="class-template-init">class template <tt class="docutils literal"><span class="pre">init</span></tt></a></h1>
|
||||
<p>Defines a named parameter enabled constructor.</p>
|
||||
<pre class="literal-block">
|
||||
template <class ParameterSpecs>
|
||||
struct init : python::def_visitor<init<ParameterSpecs> >
|
||||
{
|
||||
template <class Class>
|
||||
void def(Class& class_);
|
||||
|
||||
template <class CallPolicies>
|
||||
<em>def_visitor</em> operator[](CallPolicies const& policies) const;
|
||||
};
|
||||
</pre>
|
||||
<!-- @ignore() -->
|
||||
<div class="section">
|
||||
<h2><a id="init-requirements" name="init-requirements"><tt class="docutils literal"><span class="pre">init</span></tt> requirements</a></h2>
|
||||
<ul>
|
||||
<li><p class="first"><tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt> is an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL sequence</a> where each element is a
|
||||
model of <span class="concept">ParameterSpec</span>.</p>
|
||||
</li>
|
||||
<li><p class="first">For every <tt class="docutils literal"><span class="pre">N</span></tt> in <tt class="docutils literal"><span class="pre">[U,V]</span></tt>, where <tt class="docutils literal"><span class="pre">[U,V]</span></tt> is the <strong>arity
|
||||
range</strong> of <tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt>, <tt class="docutils literal"><span class="pre">Class</span></tt> must support these
|
||||
expressions:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="30%" />
|
||||
<col width="17%" />
|
||||
<col width="53%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head"><p class="first last">Expression</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Return type</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Requirements</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><p class="first last"><tt class="docutils literal"><span class="pre">Class(a0,</span> <span class="pre">…,</span> <span class="pre">aN)</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last">-</p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="docutils literal"><span class="pre">a0</span></tt>…<tt class="docutils literal"><span class="pre">aN</span></tt> are tagged arguments.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="template-class-callpolicies-operator-callpolicies-const" name="template-class-callpolicies-operator-callpolicies-const"><tt class="docutils literal"><span class="pre">template</span> <span class="pre"><class</span> <span class="pre">CallPolicies></span> <span class="pre">operator[](CallPolicies</span> <span class="pre">const&)</span></tt></a></h2>
|
||||
<p>Returns a <tt class="docutils literal"><span class="pre">def_visitor</span></tt> equivalent to <tt class="docutils literal"><span class="pre">*this</span></tt>, except that it
|
||||
uses CallPolicies when creating the binding.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="example" name="example">Example</a></h2>
|
||||
<pre class="literal-block">
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, x)
|
||||
BOOST_PARAMETER_KEYWORD(tag, y)
|
||||
|
||||
struct base
|
||||
{
|
||||
template <class ArgumentPack>
|
||||
base(ArgumentPack const& args)
|
||||
{
|
||||
<em>… use args …</em>
|
||||
}
|
||||
};
|
||||
|
||||
class X : base
|
||||
{
|
||||
public:
|
||||
BOOST_PARAMETER_CONSTRUCTOR(X, (base), tag,
|
||||
(required (x, *))
|
||||
(optional (y, *))
|
||||
)
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(<em>module name</em>)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = boost::parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<X>("X", no_init)
|
||||
.def(
|
||||
py::init<
|
||||
mpl::vector<tag::x(int), tag::y*(int)>
|
||||
>()
|
||||
);
|
||||
}
|
||||
</pre>
|
||||
<!-- @example.replace_emphasis('''
|
||||
assert(args[x] == 0);
|
||||
assert(args[y | 1] == 1);
|
||||
''') -->
|
||||
<!-- @example.replace_emphasis('my_module') -->
|
||||
<!-- @jam_prefix.append('import python ;') -->
|
||||
<!-- @jam_prefix.append('stage . : my_module /boost/python//boost_python ;') -->
|
||||
<!-- @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
) -->
|
||||
</div>
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id12" id="class-template-call" name="class-template-call">class template <tt class="docutils literal"><span class="pre">call</span></tt></a></h1>
|
||||
<p>Defines a <tt class="docutils literal"><span class="pre">__call__</span></tt> operator, mapped to <tt class="docutils literal"><span class="pre">operator()</span></tt> in C++.</p>
|
||||
<pre class="literal-block">
|
||||
template <class ParameterSpecs>
|
||||
struct call : python::def_visitor<call<ParameterSpecs> >
|
||||
{
|
||||
template <class Class>
|
||||
void def(Class& class_);
|
||||
|
||||
template <class CallPolicies>
|
||||
<em>def_visitor</em> operator[](CallPolicies const& policies) const;
|
||||
};
|
||||
</pre>
|
||||
<!-- @ignore() -->
|
||||
<div class="section">
|
||||
<h2><a id="call-requirements" name="call-requirements"><tt class="docutils literal"><span class="pre">call</span></tt> requirements</a></h2>
|
||||
<ul>
|
||||
<li><p class="first"><tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt> is an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL sequence</a> where each element
|
||||
except the first models <span class="concept">ParameterSpec</span>. The first element
|
||||
is the result type of <tt class="docutils literal"><span class="pre">c(…)</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first"><tt class="docutils literal"><span class="pre">Class</span></tt> must support these expressions, where <tt class="docutils literal"><span class="pre">c</span></tt> is an
|
||||
instance of <tt class="docutils literal"><span class="pre">Class</span></tt>:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="24%" />
|
||||
<col width="26%" />
|
||||
<col width="50%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head"><p class="first last">Expression</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Return type</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Requirements</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><p class="first last"><tt class="docutils literal"><span class="pre">c(a0,</span> <span class="pre">…,</span> <span class="pre">aN)</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last">Convertible to <tt class="docutils literal"><span class="pre">R</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="docutils literal"><span class="pre">a0</span></tt>…<tt class="docutils literal"><span class="pre">aN</span></tt> are tagged arguments.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>For every <tt class="docutils literal"><span class="pre">N</span></tt> in <tt class="docutils literal"><span class="pre">[U,V]</span></tt>, where <tt class="docutils literal"><span class="pre">[U,V]</span></tt> is the <strong>arity range</strong> of <tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="id3" name="id3"><tt class="docutils literal"><span class="pre">template</span> <span class="pre"><class</span> <span class="pre">CallPolicies></span> <span class="pre">operator[](CallPolicies</span> <span class="pre">const&)</span></tt></a></h2>
|
||||
<p>Returns a <tt class="docutils literal"><span class="pre">def_visitor</span></tt> equivalent to <tt class="docutils literal"><span class="pre">*this</span></tt>, except that it
|
||||
uses CallPolicies when creating the binding.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="id4" name="id4">Example</a></h2>
|
||||
<pre class="literal-block">
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, x)
|
||||
BOOST_PARAMETER_KEYWORD(tag, y)
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
|
||||
typedef parameter::parameters<
|
||||
parameter::required<tag::x>
|
||||
, parameter::optional<tag::y>
|
||||
> call_parameters;
|
||||
|
||||
class X
|
||||
{
|
||||
public:
|
||||
template <class ArgumentPack>
|
||||
int call_impl(ArgumentPack const& args)
|
||||
{
|
||||
<em>… use args …</em>
|
||||
}
|
||||
|
||||
template <class A0>
|
||||
int operator()(A0 const& a0)
|
||||
{
|
||||
return call_impl(call_parameters()(a0));
|
||||
}
|
||||
|
||||
template <class A0, class A1>
|
||||
int operator()(A0 const& a0, A1 const& a1)
|
||||
{
|
||||
return call_impl(call_parameters()(a0,a1));
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(<em>module name</em>)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<X>("X")
|
||||
.def(
|
||||
py::call<
|
||||
mpl::vector<int, tag::x(int), tag::y*(int)>
|
||||
>()
|
||||
);
|
||||
}
|
||||
</pre>
|
||||
<!-- @example.replace_emphasis('''
|
||||
assert(args[x] == 0);
|
||||
assert(args[y | 1] == 1);
|
||||
return 0;
|
||||
''') -->
|
||||
<!-- @example.replace_emphasis('my_module') -->
|
||||
<!-- @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
) -->
|
||||
</div>
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id13" id="class-template-function" name="class-template-function">class template <tt class="docutils literal"><span class="pre">function</span></tt></a></h1>
|
||||
<p>Defines a named parameter enabled member function.</p>
|
||||
<pre class="literal-block">
|
||||
template <class Fwd, class ParameterSpecs>
|
||||
struct function : python::def_visitor<function<Fwd, ParameterSpecs> >
|
||||
{
|
||||
template <class Class, class Options>
|
||||
void def(Class& class_, char const* name, Options const& options);
|
||||
};
|
||||
</pre>
|
||||
<!-- @ignore() -->
|
||||
<div class="section">
|
||||
<h2><a id="function-requirements" name="function-requirements"><tt class="docutils literal"><span class="pre">function</span></tt> requirements</a></h2>
|
||||
<ul>
|
||||
<li><p class="first"><tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt> is an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL sequence</a> where each element
|
||||
except the first models <span class="concept">ParameterSpec</span>. The first element
|
||||
is the result type of <tt class="docutils literal"><span class="pre">c.f(…)</span></tt>, where <tt class="docutils literal"><span class="pre">f</span></tt> is the member
|
||||
function.</p>
|
||||
</li>
|
||||
<li><p class="first">An instance of <tt class="docutils literal"><span class="pre">Fwd</span></tt> must support this expression:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="39%" />
|
||||
<col width="18%" />
|
||||
<col width="43%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head"><p class="first last">Expression</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Return type</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Requirements</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><p class="first last"><tt class="docutils literal"><span class="pre">fwd(boost::type<R>(),</span> <span class="pre">self,</span> <span class="pre">a0,</span> <span class="pre">…,</span> <span class="pre">aN)</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last">Convertible to <tt class="docutils literal"><span class="pre">R</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="docutils literal"><span class="pre">self</span></tt> is a reference to the object on which
|
||||
the function should be invoked. <tt class="docutils literal"><span class="pre">a0</span></tt>…<tt class="docutils literal"><span class="pre">aN</span></tt>
|
||||
are tagged arguments.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>For every <tt class="docutils literal"><span class="pre">N</span></tt> in <tt class="docutils literal"><span class="pre">[U,V]</span></tt>, where <tt class="docutils literal"><span class="pre">[U,V]</span></tt> is the <strong>arity range</strong> of <tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="id5" name="id5">Example</a></h2>
|
||||
<p>This example exports a member function <tt class="docutils literal"><span class="pre">f(int</span> <span class="pre">x,</span> <span class="pre">int</span> <span class="pre">y</span> <span class="pre">=</span> <span class="pre">…)</span></tt> to Python. The
|
||||
sequence of <span class="concept">ParameterSpec</span>'s <tt class="docutils literal"><span class="pre">mpl::vector2<tag::x(int),</span> <span class="pre">tag::y*(int)></span></tt> has
|
||||
an <strong>arity range</strong> of [2,2], so we only need one forwarding overload.</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, x)
|
||||
BOOST_PARAMETER_KEYWORD(tag, y)
|
||||
|
||||
class X
|
||||
{
|
||||
public:
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION((void), f, tag,
|
||||
(required (x, *))
|
||||
(optional (y, *, 1))
|
||||
)
|
||||
{
|
||||
<em>…</em>
|
||||
}
|
||||
};
|
||||
|
||||
struct f_fwd
|
||||
{
|
||||
template <class A0, class A1>
|
||||
void operator()(boost::type<void>, X& self, A0 const& a0, A1 const& a1)
|
||||
{
|
||||
self.f(a0, a1);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(<em>module name</em>)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = boost::parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<X>("X")
|
||||
.def("f",
|
||||
py::function<
|
||||
f_fwd
|
||||
, mpl::vector<void, tag::x(int), tag::y*(int)>
|
||||
>()
|
||||
);
|
||||
}
|
||||
</pre>
|
||||
<!-- @example.replace_emphasis('''
|
||||
assert(x == 0);
|
||||
assert(y == 1);
|
||||
''') -->
|
||||
<!-- @example.replace_emphasis('my_module') -->
|
||||
<!-- @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
) -->
|
||||
</div>
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id14" id="function-template-def" name="function-template-def">function template <tt class="docutils literal"><span class="pre">def</span></tt></a></h1>
|
||||
<p>Defines a named parameter enabled free function in the current Python scope.</p>
|
||||
<pre class="literal-block">
|
||||
template <class Fwd, class ParameterSpecs>
|
||||
void def(char const* name);
|
||||
</pre>
|
||||
<!-- @ignore() -->
|
||||
<div class="section">
|
||||
<h2><a id="def-requirements" name="def-requirements"><tt class="docutils literal"><span class="pre">def</span></tt> requirements</a></h2>
|
||||
<ul>
|
||||
<li><p class="first"><tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt> is an <a class="reference" href="../../../mpl/doc/refmanual/sequences.html">MPL sequence</a> where each element
|
||||
except the first models <span class="concept">ParameterSpec</span>. The first element
|
||||
is the result type of <tt class="docutils literal"><span class="pre">f(…)</span></tt>, where <tt class="docutils literal"><span class="pre">f</span></tt> is the function.</p>
|
||||
</li>
|
||||
<li><p class="first">An instance of <tt class="docutils literal"><span class="pre">Fwd</span></tt> must support this expression:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="39%" />
|
||||
<col width="21%" />
|
||||
<col width="40%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head"><p class="first last">Expression</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Return type</p>
|
||||
</th>
|
||||
<th class="head"><p class="first last">Requirements</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><p class="first last"><tt class="docutils literal"><span class="pre">fwd(boost::type<R>(),</span> <span class="pre">a0,</span> <span class="pre">…,</span> <span class="pre">aN)</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last">Convertible to <tt class="docutils literal"><span class="pre">R</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="docutils literal"><span class="pre">a0</span></tt>…<tt class="docutils literal"><span class="pre">aN</span></tt> are tagged arguments.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>For every <tt class="docutils literal"><span class="pre">N</span></tt> in <tt class="docutils literal"><span class="pre">[U,V]</span></tt>, where <tt class="docutils literal"><span class="pre">[U,V]</span></tt> is the <strong>arity range</strong> of <tt class="docutils literal"><span class="pre">ParameterSpecs</span></tt>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="id6" name="id6">Example</a></h2>
|
||||
<p>This example exports a function <tt class="docutils literal"><span class="pre">f(int</span> <span class="pre">x,</span> <span class="pre">int</span> <span class="pre">y</span> <span class="pre">=</span> <span class="pre">…)</span></tt> to Python. The
|
||||
sequence of <span class="concept">ParameterSpec</span>'s <tt class="docutils literal"><span class="pre">mpl::vector2<tag::x(int),</span> <span class="pre">tag::y*(int)></span></tt> has
|
||||
an <strong>arity range</strong> of [2,2], so we only need one forwarding overload.</p>
|
||||
<pre class="literal-block">
|
||||
BOOST_PARAMETER_FUNCTION((void), f, tag,
|
||||
(required (x, *))
|
||||
(optional (y, *, 1))
|
||||
)
|
||||
{
|
||||
<em>…</em>
|
||||
}
|
||||
|
||||
struct f_fwd
|
||||
{
|
||||
template <class A0, class A1>
|
||||
void operator()(boost::type<void>, A0 const& a0, A1 const& a1)
|
||||
{
|
||||
f(a0, a1);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(…)
|
||||
{
|
||||
def<
|
||||
f_fwd
|
||||
, mpl::vector<
|
||||
void, tag::x(int), tag::y*(int)
|
||||
>
|
||||
>("f");
|
||||
}
|
||||
</pre>
|
||||
<!-- @ignore() -->
|
||||
<!-- again, the undefined ``fwd`` identifier. -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id15" id="portability" name="portability">Portability</a></h1>
|
||||
<p>The Boost.Parameter Python binding library requires <em>partial template
|
||||
specialization</em>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<hr class="footer" />
|
||||
Generated on: 2007-01-03 16:40 UTC.
|
||||
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
588
doc/html/reference.html
Executable file → Normal file
588
doc/html/reference.html
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
0
doc/html/rst.css
Executable file → Normal file
0
doc/html/rst.css
Executable file → Normal file
0
doc/html/vellipsis.gif
Executable file → Normal file
0
doc/html/vellipsis.gif
Executable file → Normal file
|
Before Width: | Height: | Size: 62 B After Width: | Height: | Size: 62 B |
268
doc/index.rst
Executable file → Normal file
268
doc/index.rst
Executable file → Normal file
@@ -30,7 +30,7 @@ __ ../../../../index.htm
|
||||
can be deduced from their types.
|
||||
|
||||
.. @jam_prefix.append('''
|
||||
project test : requirements <include>. <source>/boost//headers ;''')
|
||||
project test : requirements <include>. <implicit-dependency>/boost//headers ;''')
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/parameter.hpp>
|
||||
@@ -71,22 +71,27 @@ __ ../../../../index.htm
|
||||
-------------------------------------
|
||||
|
||||
:Authors: David Abrahams, Daniel Wallin
|
||||
:Contact: dave@boost-consulting.com, dalwan01@student.umu.se
|
||||
:Organization: `Boost Consulting`_
|
||||
:Date: $Date: 2005/07/18 20:34:31 $
|
||||
:Contact: dave@boost-consulting.com, daniel@boostpro.com
|
||||
:organization: `BoostPro Computing`_
|
||||
:date: $Date: 2005/07/17 19:53:01 $
|
||||
|
||||
:Copyright: Copyright David Abrahams, Daniel Wallin 2005.
|
||||
Distributed under the Boost Software License,
|
||||
:copyright: Copyright David Abrahams, Daniel Wallin
|
||||
2005-2009. Distributed under 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)
|
||||
|
||||
.. _`Boost Consulting`: http://www.boost-consulting.com
|
||||
.. _`BoostPro Computing`: http://www.boostpro.com
|
||||
|
||||
.. _concepts: ../../../more/generic_programming.html#concept
|
||||
.. _concepts: http://www.boost.org/more/generic_programming.html#concept
|
||||
|
||||
-------------------------------------
|
||||
|
||||
[Note: this tutorial does not cover all details of the library. Please see also the `reference documentation`__\ ]
|
||||
|
||||
__ reference.html
|
||||
|
||||
.. contents:: **Table of Contents**
|
||||
:depth: 2
|
||||
|
||||
.. role:: concept
|
||||
:class: concept
|
||||
@@ -351,8 +356,8 @@ shown in the table below.
|
||||
.. _`IncidenceGraph`: ../../../graph/doc/IncidenceGraph.html
|
||||
.. _`VertexListGraph`: ../../../graph/doc/VertexListGraph.html
|
||||
.. _`DFSVisitor`: ../../../graph/doc/DFSVisitor.html
|
||||
.. _`ReadWritePropertyMap`: ../../../property_map/ReadWritePropertyMap.html
|
||||
.. _`ReadablePropertyMap`: ../../../property_map/ReadablePropertyMap.html
|
||||
.. _`ReadWritePropertyMap`: ../../../property_map/doc/ReadWritePropertyMap.html
|
||||
.. _`ReadablePropertyMap`: ../../../property_map/doc/ReadablePropertyMap.html
|
||||
|
||||
Don't be intimidated by the information in the second and third
|
||||
columns above. For the purposes of this exercise, you don't need
|
||||
@@ -778,7 +783,7 @@ signatures.
|
||||
isolate ``depth_first_search`` in a namespace containing no
|
||||
types [#using]_, but suppose we *want* it to found via ADL?
|
||||
|
||||
__ http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#225
|
||||
__ http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#225
|
||||
|
||||
It's usually a good idea to prevent functions from being considered
|
||||
for overload resolution when the passed argument types aren't
|
||||
@@ -851,6 +856,44 @@ in parentheses *and preceded by an asterix*, as follows:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
// We first need to define a few metafunction that we use in the
|
||||
// predicates below.
|
||||
|
||||
template <class G>
|
||||
struct traversal_category
|
||||
{
|
||||
typedef typename boost::graph_traits<G>::traversal_category type;
|
||||
};
|
||||
|
||||
template <class G>
|
||||
struct vertex_descriptor
|
||||
{
|
||||
typedef typename boost::graph_traits<G>::vertex_descriptor type;
|
||||
};
|
||||
|
||||
template <class G>
|
||||
struct value_type
|
||||
{
|
||||
typedef typename boost::property_traits<G>::value_type type;
|
||||
};
|
||||
|
||||
template <class G>
|
||||
struct key_type
|
||||
{
|
||||
typedef typename boost::property_traits<G>::key_type type;
|
||||
};
|
||||
|
||||
template<class Size, class IndexMap>
|
||||
boost::iterator_property_map<
|
||||
boost::default_color_type\*, IndexMap
|
||||
, boost::default_color_type, boost::default_color_type&
|
||||
>
|
||||
default_color_map(Size num_vertices, IndexMap const& index_map)
|
||||
{
|
||||
std::vector<boost::default_color_type> colors(num_vertices);
|
||||
return &colors[0];
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(void), depth_first_search, graphs
|
||||
|
||||
@@ -858,12 +901,10 @@ in parentheses *and preceded by an asterix*, as follows:
|
||||
(graph
|
||||
, **\ \*(boost::mpl::and_<
|
||||
boost::is_convertible<
|
||||
boost::graph_traits<_>::traversal_category
|
||||
, boost::incidence_graph_tag
|
||||
traversal_category<_>, boost::incidence_graph_tag
|
||||
>
|
||||
, boost::is_convertible<
|
||||
boost::graph_traits<_>::traversal_category
|
||||
, boost::vertex_list_graph_tag
|
||||
traversal_category<_>, boost::vertex_list_graph_tag
|
||||
>
|
||||
>)** ))
|
||||
|
||||
@@ -871,25 +912,21 @@ in parentheses *and preceded by an asterix*, as follows:
|
||||
(visitor, \*, boost::dfs_visitor<>()) // not checkable
|
||||
|
||||
(root_vertex
|
||||
, (typename boost::graph_traits<graphs::graph::_>::vertex_descriptor)
|
||||
, (vertex_descriptor<graphs::graph::_>)
|
||||
, \*vertices(graph).first)
|
||||
|
||||
(index_map
|
||||
, **\ \*(boost::mpl::and_<
|
||||
boost::is_integral<
|
||||
boost::property_traits<_>::value_type
|
||||
>
|
||||
boost::is_integral<value_type<_> >
|
||||
, boost::is_same<
|
||||
typename boost::graph_traits<graphs::graph::_>::vertex_descriptor
|
||||
, boost::property_traits<_>::key_type
|
||||
vertex_descriptor<graphs::graph::_>, key_type<_>
|
||||
>
|
||||
>)**
|
||||
, get(boost::vertex_index,graph))
|
||||
|
||||
(in_out(color_map)
|
||||
, **\ \*(boost::is_same<
|
||||
typename boost::graph_traits<graphs::graph::_>::vertex_descriptor
|
||||
, boost::property_traits<_>::key_type
|
||||
vertex_descriptor<graphs::graph::_>, key_type<_>
|
||||
>)**
|
||||
, default_color_map(num_vertices(graph), index_map) )
|
||||
)
|
||||
@@ -897,6 +934,8 @@ in parentheses *and preceded by an asterix*, as follows:
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/parameter.hpp>
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
#include <boost/graph/depth_first_search.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME((_graph, graphs) graph)
|
||||
BOOST_PARAMETER_NAME((_visitor, graphs) visitor)
|
||||
@@ -905,38 +944,37 @@ in parentheses *and preceded by an asterix*, as follows:
|
||||
BOOST_PARAMETER_NAME((_color_map, graphs) color_map)
|
||||
|
||||
using boost::mpl::_;
|
||||
|
||||
namespace boost
|
||||
{
|
||||
struct incidence_graph_tag {};
|
||||
struct vertex_list_graph_tag {};
|
||||
|
||||
int vertex_index = 0;
|
||||
|
||||
template <class T>
|
||||
struct graph_traits
|
||||
{
|
||||
typedef int traversal_category;
|
||||
typedef int vertex_descriptor;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct property_traits
|
||||
{
|
||||
typedef int value_type;
|
||||
typedef int key_type;
|
||||
};
|
||||
|
||||
template <class T = int>
|
||||
struct dfs_visitor
|
||||
{};
|
||||
}''')
|
||||
''')
|
||||
|
||||
.. @example.append('''
|
||||
{}''')
|
||||
{}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> G;
|
||||
|
||||
enum {u, v, w, x, y, z, N};
|
||||
typedef std::pair<int, int> E;
|
||||
E edges[] = {E(u, v), E(u, x), E(x, v), E(y, x), E(v, y), E(w, y),
|
||||
E(w,z), E(z, z)};
|
||||
G g(edges, edges + sizeof(edges) / sizeof(E), N);
|
||||
|
||||
depth_first_search(g);
|
||||
depth_first_search(g, _root_vertex = (int)x);
|
||||
}
|
||||
''')
|
||||
|
||||
.. @test('compile')
|
||||
|
||||
Note the use of the nested `tag::_`. This is a shortcut for::
|
||||
|
||||
value_type<boost::mpl::_2, tag>
|
||||
|
||||
.. @ignore()
|
||||
|
||||
Intended to be used to access preceding arguments types in the
|
||||
predicates.
|
||||
|
||||
__ ../../../mpl/doc/refmanual/metafunction.html
|
||||
|
||||
We acknowledge that this signature is pretty hairy looking.
|
||||
@@ -1107,7 +1145,7 @@ be used within the body of a class::
|
||||
struct callable2
|
||||
{
|
||||
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
|
||||
(void), operator(), tag, (required (arg1,(int))(arg2,(int))))
|
||||
(void), call, tag, (required (arg1,(int))(arg2,(int))))
|
||||
{
|
||||
std::cout << arg1 << ", " << arg2 << std::endl;
|
||||
}
|
||||
@@ -1115,7 +1153,9 @@ be used within the body of a class::
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>''')
|
||||
#include <iostream>
|
||||
using namespace boost::parameter;
|
||||
''')
|
||||
|
||||
.. @test('compile')
|
||||
|
||||
@@ -1126,7 +1166,7 @@ arguments on to a separate implementation function::
|
||||
struct callable2
|
||||
{
|
||||
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
|
||||
(void), operator(), tag, (required (arg1,(int))(arg2,(int))))
|
||||
(void), call, tag, (required (arg1,(int))(arg2,(int))))
|
||||
{
|
||||
call_impl(arg1,arg2);
|
||||
}
|
||||
@@ -1138,10 +1178,40 @@ arguments on to a separate implementation function::
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME(arg1)
|
||||
BOOST_PARAMETER_NAME(arg2)''')
|
||||
BOOST_PARAMETER_NAME(arg2)
|
||||
using namespace boost::parameter;
|
||||
''')
|
||||
|
||||
.. @test('compile')
|
||||
|
||||
Static Member Functions
|
||||
=======================
|
||||
|
||||
To expose a static member function, simply insert the keyword
|
||||
“``static``” before the function name:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
BOOST_PARAMETER_NAME(arg1)
|
||||
|
||||
struct somebody
|
||||
{
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION(
|
||||
(void), **static** f, tag, (optional (arg1,(int),0)))
|
||||
{
|
||||
std::cout << arg1 << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
using namespace boost::parameter;
|
||||
''')
|
||||
|
||||
.. @test('compile')
|
||||
|
||||
|
||||
------------------------------
|
||||
Parameter-Enabled Constructors
|
||||
------------------------------
|
||||
@@ -1334,10 +1404,10 @@ separately)::
|
||||
using boost::mpl::_;
|
||||
|
||||
typedef parameter::parameters<
|
||||
required<tag::class_type, is_class<_> >
|
||||
, optional<tag::base_list, mpl::is_sequence<_> >
|
||||
, optional<tag::held_type>
|
||||
, optional<tag::copyable>
|
||||
required<tag::class_type, boost::is_class<_> >
|
||||
, parameter::optional<tag::base_list, mpl::is_sequence<_> >
|
||||
, parameter::optional<tag::held_type>
|
||||
, parameter::optional<tag::copyable>
|
||||
> class_signature;
|
||||
|
||||
}}
|
||||
@@ -1346,6 +1416,7 @@ separately)::
|
||||
#include <boost/parameter.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <memory>
|
||||
|
||||
using namespace boost::parameter;
|
||||
@@ -1372,12 +1443,13 @@ separately)::
|
||||
Argument Packs and Parameter Extraction
|
||||
---------------------------------------
|
||||
|
||||
Next, within the body of ``class_`` , we use the |ParameterSpec|\
|
||||
's nested ``::bind< … >`` template to bundle the actual arguments
|
||||
into an |ArgumentPack|_ type, and then use the library's ``binding<
|
||||
… >`` metafunction to extract “logical parameters”. Note that
|
||||
defaults are specified by supplying an optional third argument to
|
||||
``binding< … >``::
|
||||
Next, within the body of ``class_`` , we use the |ParameterSpec|\ 's
|
||||
nested ``::bind< … >`` template to bundle the actual arguments into an
|
||||
|ArgumentPack|_ type, and then use the library's ``value_type< … >``
|
||||
metafunction to extract “logical parameters”. ``value_type< … >`` is
|
||||
a lot like ``binding< … >``, but no reference is added to the actual
|
||||
argument type. Note that defaults are specified by passing it an
|
||||
optional third argument::
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -1395,16 +1467,16 @@ defaults are specified by supplying an optional third argument to
|
||||
args;
|
||||
|
||||
// Extract first logical parameter.
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::class_type>::type class_type;
|
||||
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::base_list, bases<> >::type base_list;
|
||||
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::held_type, class_type>::type held_type;
|
||||
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::copyable, void>::type copyable;
|
||||
};
|
||||
|
||||
@@ -1506,12 +1578,12 @@ parameters deducible::
|
||||
typedef parameter::parameters<
|
||||
required<tag::class_type, is_class<_> >
|
||||
|
||||
, optional<
|
||||
, parameter::optional<
|
||||
deduced<tag::base_list>
|
||||
, is_base_and_derived<detail::bases_base,_>
|
||||
>
|
||||
|
||||
, optional<
|
||||
, parameter::optional<
|
||||
deduced<tag::held_type>
|
||||
, mpl::not_<
|
||||
mpl::or_<
|
||||
@@ -1521,11 +1593,12 @@ parameters deducible::
|
||||
>
|
||||
>
|
||||
|
||||
, optional<deduced<tag::copyable>, is_same<noncopyable,_> >
|
||||
, parameter::optional<deduced<tag::copyable>, is_same<noncopyable,_> >
|
||||
|
||||
> class_signature;
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
namespace boost { namespace python {''')
|
||||
|
||||
.. @example.append('''
|
||||
@@ -1543,16 +1616,16 @@ parameters deducible::
|
||||
args;
|
||||
|
||||
// Extract first logical parameter.
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::class_type>::type class_type;
|
||||
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::base_list, bases<> >::type base_list;
|
||||
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::held_type, class_type>::type held_type;
|
||||
|
||||
typedef typename parameter::binding<
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::copyable, void>::type copyable;
|
||||
};
|
||||
|
||||
@@ -1727,7 +1800,7 @@ its function call operator:
|
||||
Note that because of the `forwarding problem`_, ``parameter::parameters::operator()``
|
||||
can't accept non-const rvalues.
|
||||
|
||||
.. _`forwarding problem`: http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
|
||||
.. _`forwarding problem`: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
|
||||
|
||||
Extracting Parameter Types
|
||||
==========================
|
||||
@@ -1773,15 +1846,13 @@ function template and allow *it* to do type deduction::
|
||||
Occasionally one needs to deduce argument types without an extra
|
||||
layer of function call. For example, suppose we wanted to return
|
||||
twice the value of the ``index`` parameter? In that
|
||||
case we can use the ``binding< … >`` metafunction introduced
|
||||
case we can use the ``value_type< … >`` metafunction introduced
|
||||
`earlier`__::
|
||||
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
template <class ArgumentPack>
|
||||
typename remove_reference<
|
||||
typename parameter::binding<ArgumentPack, tag::index, int>::type
|
||||
>::type
|
||||
typename parameter::value_type<ArgumentPack, tag::index, int>::type
|
||||
twice_index(ArgumentPack const& args)
|
||||
{
|
||||
return 2 * args[_index|42];
|
||||
@@ -1795,39 +1866,20 @@ case we can use the ``binding< … >`` metafunction introduced
|
||||
#include <cassert>
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
using boost::remove_reference;''')
|
||||
|
||||
Note that the ``remove_reference< … >`` dance is necessary because
|
||||
``binding< … >`` will return a reference type when the argument
|
||||
is bound in the argument pack. If we don't strip the reference we
|
||||
end up returning a reference to the temporary created in the ``2 * …``
|
||||
expression. A convenient shortcut would be to use the ``value_type< … >``
|
||||
metafunction:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
template <class ArgumentPack>
|
||||
typename **parameter::value_type<ArgumentPack, tag::index, int>**::type
|
||||
twice_index(ArgumentPack const& args)
|
||||
{
|
||||
return 2 * args[_index|42];
|
||||
}
|
||||
|
||||
.. @example.wrap('namespace with_value_type {', '''
|
||||
int six = twice_index(_index = 3);
|
||||
}''')
|
||||
|
||||
.. TODO: binding<> returns a reference. We should use value_type<> here.
|
||||
''')
|
||||
|
||||
.. @example.append('''
|
||||
int main()
|
||||
{
|
||||
assert(six == 6);
|
||||
assert(with_value_type::six == 6);
|
||||
}''')
|
||||
|
||||
.. @test('run', howmany='all')
|
||||
|
||||
Note that if we had used ``binding< … >`` rather than ``value_type< …
|
||||
>``, we would end up returning a reference to the temporary created in
|
||||
the ``2 * …`` expression.
|
||||
|
||||
__ binding_intro_
|
||||
|
||||
Lazy Default Computation
|
||||
@@ -1883,12 +1935,10 @@ object.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
using boost::bind;
|
||||
using boost::ref;
|
||||
|
||||
typename parameter::binding<
|
||||
ArgumentPack, tag::s3, std::string
|
||||
>::type s3 = args[_s3 **|| bind(std::plus<std::string>(), ref(s1), ref(s2))** ];
|
||||
>::type s3 = args[_s3
|
||||
**|| boost::bind(std::plus<std::string>(), boost::ref(s1), boost::ref(s2))** ];
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/bind.hpp>
|
||||
@@ -2235,7 +2285,7 @@ enclosing namespace without qualification::
|
||||
Follow `this link`__ for documentation on how to expose
|
||||
Boost.Parameter-enabled functions to Python with `Boost.Python`_.
|
||||
|
||||
__ python.html
|
||||
__ ../../../parameter_python/doc/html/index.html
|
||||
|
||||
===========
|
||||
Reference
|
||||
|
||||
778
doc/python.rst
778
doc/python.rst
@@ -1,778 +0,0 @@
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
The Boost Parameter Library Python Binding Documentation
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
:Authors: Daniel Wallin
|
||||
:Contact: dalwan01@student.umu.se
|
||||
:organization: `Boost Consulting`_
|
||||
:date: $Date$
|
||||
|
||||
:copyright: Copyright David Abrahams, Daniel Wallin
|
||||
2005. Distributed under 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)
|
||||
|
||||
:abstract: Makes it possible to bind Boost.Parameter-enabled
|
||||
functions, operators and constructors to Python.
|
||||
|
||||
|(logo)|__
|
||||
|
||||
.. |(logo)| image:: ../../../../boost.png
|
||||
:alt: Boost
|
||||
|
||||
__ ../../../../index.htm
|
||||
|
||||
.. _`Boost Consulting`: http://www.boost-consulting.com
|
||||
|
||||
|
||||
.. role:: class
|
||||
:class: class
|
||||
|
||||
.. role:: concept
|
||||
:class: concept
|
||||
|
||||
.. role:: function
|
||||
:class: function
|
||||
|
||||
.. |ParameterSpec| replace:: :concept:`ParameterSpec`
|
||||
|
||||
.. contents::
|
||||
:depth: 1
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
``boost/parameter/python.hpp`` introduces a group of |def_visitors|_ that can
|
||||
be used to easily expose Boost.Parameter-enabled member functions to Python with
|
||||
Boost.Python. It also provides a function template ``def()`` that can be used
|
||||
to expose Boost.Parameter-enabled free functions.
|
||||
|
||||
.. |def_visitor| replace:: ``def_visitor``
|
||||
.. |def_visitors| replace:: ``def_visitors``
|
||||
|
||||
.. _def_visitor: def_visitors_
|
||||
.. _def_visitors: ../../../python/doc/v2/def_visitor.html
|
||||
|
||||
When binding a Boost.Parameter enabled function, the keyword tags
|
||||
must be specified. Additionally, because Boost.Parameter enabled
|
||||
functions are templates, the desired function signature must be
|
||||
specified.
|
||||
|
||||
.. The keyword tags are specified as an `MPL Sequence`_, using the
|
||||
pointer qualifications described in |ParameterSpec|_ below. The
|
||||
signature is also specifid as an `MPL sequence`_ of parameter
|
||||
types. Additionally, ``boost::parameter::python::function`` and
|
||||
``boost::parameter::python::def`` requires a class with forwarding
|
||||
overloads. We will take a closer look at how this is done in the
|
||||
tutorial section below.
|
||||
|
||||
The keyword tags and associated argument types are specified as an `MPL
|
||||
Sequence`_, using the function type syntax described in |ParameterSpec|_
|
||||
below. Additionally, ``boost::parameter::python::function`` and
|
||||
``boost::parameter::python::def`` requires a class with forwarding overloads.
|
||||
We will take a closer look at how this is done in the tutorial section below.
|
||||
|
||||
.. The last two sentences are terribly vague. Which namespace is
|
||||
.. ``function`` in? Isn't the return type always needed? What
|
||||
.. else are we going to do other than pass these sequences to
|
||||
.. function?
|
||||
|
||||
.. _`MPL Sequence`: ../../../mpl/doc/refmanual/sequences.html
|
||||
.. _parameterspec: `concept ParameterSpec`_
|
||||
|
||||
Tutorial
|
||||
--------
|
||||
|
||||
In this section we will outline the steps needed to bind a simple
|
||||
Boost.Parameter-enabled member function to Python. Knowledge of the
|
||||
Boost.Parameter macros_ are required to understand this section.
|
||||
|
||||
.. _macros: index.html
|
||||
|
||||
The class and member function we are interested in binding looks
|
||||
like this:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
|
||||
// First the keywords
|
||||
BOOST_PARAMETER_KEYWORD(tag, title)
|
||||
BOOST_PARAMETER_KEYWORD(tag, width)
|
||||
BOOST_PARAMETER_KEYWORD(tag, height)
|
||||
|
||||
class window
|
||||
{
|
||||
public:
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION(
|
||||
(void), open, tag,
|
||||
(required (title, (std::string)))
|
||||
(optional (width, (unsigned), 400)
|
||||
(height, (unsigned), 400))
|
||||
)
|
||||
{
|
||||
*… function implementation …*
|
||||
}
|
||||
};
|
||||
|
||||
.. @example.prepend('#include <cassert>')
|
||||
.. @example.replace_emphasis('''
|
||||
assert(title == "foo");
|
||||
assert(height == 20);
|
||||
assert(width == 400);
|
||||
''')
|
||||
|
||||
It defines a set of overloaded member functions called ``open`` with one
|
||||
required parameter and two optional ones. To bind this member function to
|
||||
Python we use the binding utility ``boost::parameter::python::function``.
|
||||
``boost::parameter::python::function`` is a |def_visitor|_ that we'll instantiate
|
||||
and pass to ``boost::python::class_::def()``.
|
||||
|
||||
To use ``boost::parameter::python::function`` we first need to define
|
||||
a class with forwarding overloads. This is needed because ``window::open()``
|
||||
is a function template, so we can't refer to it in any other way.
|
||||
|
||||
::
|
||||
|
||||
struct open_fwd
|
||||
{
|
||||
template <class A0, class A1, class A2>
|
||||
void operator()(
|
||||
boost::type<void>, window& self
|
||||
, A0 const& a0, A1 const& a1, A2 const& a2
|
||||
)
|
||||
{
|
||||
self.open(a0, a1, a2);
|
||||
}
|
||||
};
|
||||
|
||||
The first parameter, ``boost::type<void>``, tells the forwarding overload
|
||||
what the return type should be. In this case we know that it's always void
|
||||
but in some cases, when we are exporting several specializations of a
|
||||
Boost.Parameter-enabled template, we need to use that parameter to
|
||||
deduce the return type.
|
||||
|
||||
``window::open()`` takes a total of 3 parameters, so the forwarding function
|
||||
needs to take three parameters as well.
|
||||
|
||||
.. Note::
|
||||
|
||||
We only need one overload in the forwarding class, despite the
|
||||
fact that there are two optional parameters. There are special
|
||||
circumstances when several overload are needed; see
|
||||
`special keywords`_.
|
||||
|
||||
Next we'll define the module and export the class:
|
||||
|
||||
::
|
||||
|
||||
BOOST_PYTHON_MODULE(my_module)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = boost::parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<window>("window")
|
||||
.def(
|
||||
"open", py::function<
|
||||
open_fwd
|
||||
, mpl::vector<
|
||||
void
|
||||
, tag::title(std::string)
|
||||
, tag::width*(unsigned)
|
||||
, tag::height*(unsigned)
|
||||
>
|
||||
>()
|
||||
);
|
||||
}
|
||||
|
||||
.. @jam_prefix.append('import python ;')
|
||||
.. @jam_prefix.append('stage . : my_module /boost/python//boost_python ;')
|
||||
.. @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
, howmany = 'all'
|
||||
)
|
||||
|
||||
.. @del jam_prefix[:]
|
||||
|
||||
``py::function`` is passed two parameters. The first one is the class with
|
||||
forwarding overloads that we defined earlier. The second one is an `MPL
|
||||
Sequence`_ with the keyword tag types and argument types for the function
|
||||
specified as function types. The pointer syntax used in ``tag::width*`` and
|
||||
``tag::height*`` means that the parameter is optional. The first element of
|
||||
the `MPL Sequence`_ is the return type of the function, in this case ``void``,
|
||||
which is passed as the first argument to ``operator()`` in the forwarding
|
||||
class.
|
||||
|
||||
.. The
|
||||
pointer syntax means that the parameter is optional, so in this case
|
||||
``width`` and ``height`` are optional parameters. The third parameter
|
||||
is an `MPL Sequence`_ with the desired function signature. The return type comes first, and
|
||||
then the parameter types:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
mpl::vector<void, std::string, unsigned, unsigned>
|
||||
*return type* *title* *width* *height*
|
||||
|
||||
.. @ignore()
|
||||
|
||||
That's it! This class can now be used in Python with the expected syntax::
|
||||
|
||||
>>> w = my_module.window()
|
||||
>>> w.open(title = "foo", height = 20)
|
||||
|
||||
.. @example.prepend('import my_module')
|
||||
.. @run_python(module_path = my_module)
|
||||
|
||||
.. Sorry to say this at such a late date, but this syntax really
|
||||
.. strikes me as cumbersome. Couldn't we do something like:
|
||||
|
||||
class_<window>("window")
|
||||
.def(
|
||||
"open",
|
||||
(void (*)(
|
||||
tag::title(std::string),
|
||||
tag::width*(unsigned),
|
||||
tag::height*(unsigned))
|
||||
)0
|
||||
);
|
||||
|
||||
or at least:
|
||||
|
||||
class_<window>("window")
|
||||
.def(
|
||||
"open",
|
||||
mpl::vector<
|
||||
void,
|
||||
tag::title(std::string),
|
||||
tag::width*(unsigned),
|
||||
tag::height*(unsigned)
|
||||
>()
|
||||
);
|
||||
|
||||
assuming, that is, that we will have to repeat the tags (yes,
|
||||
users of broken compilers will have to give us function pointer
|
||||
types instead).
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
concept |ParameterSpec|
|
||||
-----------------------
|
||||
|
||||
A |ParameterSpec| is a function type ``K(T)`` that describes both the keyword tag,
|
||||
``K``, and the argument type, ``T``, for a parameter.
|
||||
|
||||
``K`` is either:
|
||||
|
||||
* A *required* keyword of the form ``Tag``
|
||||
* **or**, an *optional* keyword of the form ``Tag*``
|
||||
* **or**, a *special* keyword of the form ``Tag**``
|
||||
|
||||
where ``Tag`` is a keyword tag type, as used in a specialization
|
||||
of |keyword|__.
|
||||
|
||||
.. |keyword| replace:: ``boost::parameter::keyword``
|
||||
__ ../../../parameter/doc/html/reference.html#keyword
|
||||
|
||||
The **arity range** for an `MPL Sequence`_ of |ParameterSpec|'s is
|
||||
defined as the closed range:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
[ mpl::size<S> - number of *special* keyword tags in ``S``, mpl::size<S> ]
|
||||
|
||||
For example, the **arity range** of ``mpl::vector2<x(int),y(int)>`` is ``[2,2]``,
|
||||
the **arity range** of ``mpl::vector2<x(int),y*(int)>`` is ``[2,2]`` and the
|
||||
**arity range** of ``mpl::vector2<x(int),y**(int)>`` is ``[1,2]``.
|
||||
|
||||
|
||||
|
||||
*special* keywords
|
||||
---------------------------------
|
||||
|
||||
Sometimes it is desirable to have a default value for a parameter that differ
|
||||
in type from the parameter. This technique is useful for doing simple tag-dispatching
|
||||
based on the presence of a parameter. For example:
|
||||
|
||||
.. An example_ of this is given in the Boost.Parameter
|
||||
docs. The example uses a different technique, but could also have been written like this:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
namespace core
|
||||
{
|
||||
template <class ArgumentPack>
|
||||
void dfs_dispatch(ArgumentPack const& args, mpl::false\_)
|
||||
{
|
||||
*…compute and use default color map…*
|
||||
}
|
||||
|
||||
template <class ArgumentPack, class ColorMap>
|
||||
void dfs_dispatch(ArgumentPack const& args, ColorMap colormap)
|
||||
{
|
||||
*…use colormap…*
|
||||
}
|
||||
}
|
||||
|
||||
template <class ArgumentPack>
|
||||
void depth_first_search(ArgumentPack const& args)
|
||||
{
|
||||
core::dfs_dispatch(args, args[color | mpl::false_()]);
|
||||
}
|
||||
|
||||
.. @example.prepend('''
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/parameters.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <cassert>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, color);
|
||||
|
||||
typedef boost::parameter::parameters<tag::color> params;
|
||||
|
||||
namespace mpl = boost::mpl;
|
||||
''')
|
||||
|
||||
.. @example.replace_emphasis('''
|
||||
assert(args[color | 1] == 1);
|
||||
''')
|
||||
|
||||
.. @example.replace_emphasis('''
|
||||
assert(args[color | 1] == 0);
|
||||
''')
|
||||
|
||||
.. @example.append('''
|
||||
int main()
|
||||
{
|
||||
depth_first_search(params()());
|
||||
depth_first_search(params()(color = 0));
|
||||
}''')
|
||||
|
||||
.. @build()
|
||||
|
||||
.. .. _example: index.html#dispatching-based-on-the-presence-of-a-default
|
||||
|
||||
In the above example the type of the default for ``color`` is ``mpl::false_``, a
|
||||
type that is distinct from any color map that the user might supply.
|
||||
|
||||
When binding the case outlined above, the default type for ``color`` will not
|
||||
be convertible to the parameter type. Therefore we need to tag the ``color``
|
||||
keyword as a *special* keyword. This is done by specifying the tag as
|
||||
``tag::color**`` when binding the function (see `concept ParameterSpec`_ for
|
||||
more details on the tagging). By doing this we tell the binding functions that
|
||||
it needs to generate two overloads, one with the ``color`` parameter present
|
||||
and one without. Had there been two *special* keywords, four overloads would
|
||||
need to be generated. The number of generated overloads is equal to 2\
|
||||
:sup:`N`, where ``N`` is the number of *special* keywords.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
class template ``init``
|
||||
-----------------------
|
||||
|
||||
Defines a named parameter enabled constructor.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
template <class ParameterSpecs>
|
||||
struct init : python::def_visitor<init<ParameterSpecs> >
|
||||
{
|
||||
template <class Class>
|
||||
void def(Class& class\_);
|
||||
|
||||
template <class CallPolicies>
|
||||
*def\_visitor* operator[](CallPolicies const& policies) const;
|
||||
};
|
||||
|
||||
.. @ignore()
|
||||
|
||||
``init`` requirements
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* ``ParameterSpecs`` is an `MPL sequence`_ where each element is a
|
||||
model of |ParameterSpec|.
|
||||
* For every ``N`` in ``[U,V]``, where ``[U,V]`` is the **arity
|
||||
range** of ``ParameterSpecs``, ``Class`` must support these
|
||||
expressions:
|
||||
|
||||
======================= ============= =========================================
|
||||
Expression Return type Requirements
|
||||
======================= ============= =========================================
|
||||
``Class(a0, …, aN)`` \- ``a0``\ …\ ``aN`` are tagged arguments.
|
||||
======================= ============= =========================================
|
||||
|
||||
|
||||
|
||||
``template <class CallPolicies> operator[](CallPolicies const&)``
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Returns a ``def_visitor`` equivalent to ``*this``, except that it
|
||||
uses CallPolicies when creating the binding.
|
||||
|
||||
|
||||
Example
|
||||
~~~~~~~
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, x)
|
||||
BOOST_PARAMETER_KEYWORD(tag, y)
|
||||
|
||||
struct base
|
||||
{
|
||||
template <class ArgumentPack>
|
||||
base(ArgumentPack const& args)
|
||||
{
|
||||
*… use args …*
|
||||
}
|
||||
};
|
||||
|
||||
class X : base
|
||||
{
|
||||
public:
|
||||
BOOST_PARAMETER_CONSTRUCTOR(X, (base), tag,
|
||||
(required (x, \*))
|
||||
(optional (y, \*))
|
||||
)
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(*module name*)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = boost::parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<X>("X", no_init)
|
||||
.def(
|
||||
py::init<
|
||||
mpl::vector<tag::x(int), tag::y\*(int)>
|
||||
>()
|
||||
);
|
||||
}
|
||||
|
||||
.. @example.replace_emphasis('''
|
||||
assert(args[x] == 0);
|
||||
assert(args[y | 1] == 1);
|
||||
''')
|
||||
|
||||
.. @example.replace_emphasis('my_module')
|
||||
|
||||
.. @jam_prefix.append('import python ;')
|
||||
.. @jam_prefix.append('stage . : my_module /boost/python//boost_python ;')
|
||||
.. @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
class template ``call``
|
||||
-----------------------
|
||||
|
||||
Defines a ``__call__`` operator, mapped to ``operator()`` in C++.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
template <class ParameterSpecs>
|
||||
struct call : python::def_visitor<call<ParameterSpecs> >
|
||||
{
|
||||
template <class Class>
|
||||
void def(Class& class\_);
|
||||
|
||||
template <class CallPolicies>
|
||||
*def\_visitor* operator[](CallPolicies const& policies) const;
|
||||
};
|
||||
|
||||
.. @ignore()
|
||||
|
||||
``call`` requirements
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* ``ParameterSpecs`` is an `MPL sequence`_ where each element
|
||||
except the first models |ParameterSpec|. The first element
|
||||
is the result type of ``c(…)``.
|
||||
* ``Class`` must support these expressions, where ``c`` is an
|
||||
instance of ``Class``:
|
||||
|
||||
=================== ==================== =======================================
|
||||
Expression Return type Requirements
|
||||
=================== ==================== =======================================
|
||||
``c(a0, …, aN)`` Convertible to ``R`` ``a0``\ …\ ``aN`` are tagged arguments.
|
||||
=================== ==================== =======================================
|
||||
|
||||
For every ``N`` in ``[U,V]``, where ``[U,V]`` is the **arity range** of ``ParameterSpecs``.
|
||||
|
||||
|
||||
``template <class CallPolicies> operator[](CallPolicies const&)``
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Returns a ``def_visitor`` equivalent to ``*this``, except that it
|
||||
uses CallPolicies when creating the binding.
|
||||
|
||||
|
||||
Example
|
||||
~~~~~~~
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, x)
|
||||
BOOST_PARAMETER_KEYWORD(tag, y)
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
|
||||
typedef parameter::parameters<
|
||||
parameter::required<tag::x>
|
||||
, parameter::optional<tag::y>
|
||||
> call_parameters;
|
||||
|
||||
class X
|
||||
{
|
||||
public:
|
||||
template <class ArgumentPack>
|
||||
int call_impl(ArgumentPack const& args)
|
||||
{
|
||||
*… use args …*
|
||||
}
|
||||
|
||||
template <class A0>
|
||||
int operator()(A0 const& a0)
|
||||
{
|
||||
return call_impl(call_parameters()(a0));
|
||||
}
|
||||
|
||||
template <class A0, class A1>
|
||||
int operator()(A0 const& a0, A1 const& a1)
|
||||
{
|
||||
return call_impl(call_parameters()(a0,a1));
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(*module name*)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<X>("X")
|
||||
.def(
|
||||
py::call<
|
||||
mpl::vector<int, tag::x(int), tag::y\*(int)>
|
||||
>()
|
||||
);
|
||||
}
|
||||
|
||||
.. @example.replace_emphasis('''
|
||||
assert(args[x] == 0);
|
||||
assert(args[y | 1] == 1);
|
||||
return 0;
|
||||
''')
|
||||
|
||||
.. @example.replace_emphasis('my_module')
|
||||
|
||||
.. @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
class template ``function``
|
||||
---------------------------
|
||||
|
||||
Defines a named parameter enabled member function.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
template <class Fwd, class ParameterSpecs>
|
||||
struct function : python::def_visitor<function<Fwd, ParameterSpecs> >
|
||||
{
|
||||
template <class Class, class Options>
|
||||
void def(Class& class\_, char const* name, Options const& options);
|
||||
};
|
||||
|
||||
.. @ignore()
|
||||
|
||||
``function`` requirements
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* ``ParameterSpecs`` is an `MPL sequence`_ where each element
|
||||
except the first models |ParameterSpec|. The first element
|
||||
is the result type of ``c.f(…)``, where ``f`` is the member
|
||||
function.
|
||||
* An instance of ``Fwd`` must support this expression:
|
||||
|
||||
============================================ ==================== =================================================
|
||||
Expression Return type Requirements
|
||||
============================================ ==================== =================================================
|
||||
``fwd(boost::type<R>(), self, a0, …, aN)`` Convertible to ``R`` ``self`` is a reference to the object on which
|
||||
the function should be invoked. ``a0``\ …\ ``aN``
|
||||
are tagged arguments.
|
||||
============================================ ==================== =================================================
|
||||
|
||||
For every ``N`` in ``[U,V]``, where ``[U,V]`` is the **arity range** of ``ParameterSpecs``.
|
||||
|
||||
|
||||
Example
|
||||
~~~~~~~
|
||||
|
||||
This example exports a member function ``f(int x, int y = …)`` to Python. The
|
||||
sequence of |ParameterSpec|'s ``mpl::vector2<tag::x(int), tag::y*(int)>`` has
|
||||
an **arity range** of [2,2], so we only need one forwarding overload.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/python.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
BOOST_PARAMETER_KEYWORD(tag, x)
|
||||
BOOST_PARAMETER_KEYWORD(tag, y)
|
||||
|
||||
class X
|
||||
{
|
||||
public:
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION((void), f, tag,
|
||||
(required (x, \*))
|
||||
(optional (y, \*, 1))
|
||||
)
|
||||
{
|
||||
*…*
|
||||
}
|
||||
};
|
||||
|
||||
struct f_fwd
|
||||
{
|
||||
template <class A0, class A1>
|
||||
void operator()(boost::type<void>, X& self, A0 const& a0, A1 const& a1)
|
||||
{
|
||||
self.f(a0, a1);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(*module name*)
|
||||
{
|
||||
using namespace boost::python;
|
||||
namespace py = boost::parameter::python;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class_<X>("X")
|
||||
.def("f",
|
||||
py::function<
|
||||
f_fwd
|
||||
, mpl::vector<void, tag::x(int), tag::y\*(int)>
|
||||
>()
|
||||
);
|
||||
}
|
||||
|
||||
.. @example.replace_emphasis('''
|
||||
assert(x == 0);
|
||||
assert(y == 1);
|
||||
''')
|
||||
|
||||
.. @example.replace_emphasis('my_module')
|
||||
|
||||
.. @my_module = build(
|
||||
output = 'my_module'
|
||||
, target_rule = 'python-extension'
|
||||
, input = '/boost/python//boost_python'
|
||||
)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
function template ``def``
|
||||
-------------------------
|
||||
|
||||
Defines a named parameter enabled free function in the current Python scope.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
template <class Fwd, class ParameterSpecs>
|
||||
void def(char const* name);
|
||||
|
||||
.. @ignore()
|
||||
|
||||
``def`` requirements
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* ``ParameterSpecs`` is an `MPL sequence`_ where each element
|
||||
except the first models |ParameterSpec|. The first element
|
||||
is the result type of ``f(…)``, where ``f`` is the function.
|
||||
* An instance of ``Fwd`` must support this expression:
|
||||
|
||||
====================================== ==================== =======================================
|
||||
Expression Return type Requirements
|
||||
====================================== ==================== =======================================
|
||||
``fwd(boost::type<R>(), a0, …, aN)`` Convertible to ``R`` ``a0``\ …\ ``aN`` are tagged arguments.
|
||||
====================================== ==================== =======================================
|
||||
|
||||
For every ``N`` in ``[U,V]``, where ``[U,V]`` is the **arity range** of ``ParameterSpecs``.
|
||||
|
||||
|
||||
Example
|
||||
~~~~~~~
|
||||
|
||||
This example exports a function ``f(int x, int y = …)`` to Python. The
|
||||
sequence of |ParameterSpec|'s ``mpl::vector2<tag::x(int), tag::y*(int)>`` has
|
||||
an **arity range** of [2,2], so we only need one forwarding overload.
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
BOOST_PARAMETER_FUNCTION((void), f, tag,
|
||||
(required (x, \*))
|
||||
(optional (y, \*, 1))
|
||||
)
|
||||
{
|
||||
*…*
|
||||
}
|
||||
|
||||
struct f_fwd
|
||||
{
|
||||
template <class A0, class A1>
|
||||
void operator()(boost::type<void>, A0 const& a0, A1 const& a1)
|
||||
{
|
||||
f(a0, a1);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(…)
|
||||
{
|
||||
def<
|
||||
f_fwd
|
||||
, mpl::vector<
|
||||
void, tag::\ x(int), tag::\ y\*(int)
|
||||
>
|
||||
>("f");
|
||||
}
|
||||
|
||||
.. @ignore()
|
||||
|
||||
.. again, the undefined ``fwd`` identifier.
|
||||
|
||||
Portability
|
||||
-----------
|
||||
|
||||
The Boost.Parameter Python binding library requires *partial template
|
||||
specialization*.
|
||||
|
||||
20
doc/reference.rst
Executable file → Normal file
20
doc/reference.rst
Executable file → Normal file
@@ -3,12 +3,12 @@
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
:Authors: David Abrahams, Daniel Wallin
|
||||
:Contact: dave@boost-consulting.com, dalwan01@student.umu.se
|
||||
:organization: `Boost Consulting`_
|
||||
:Contact: dave@boost-consulting.com, daniel@boostpro.com
|
||||
:organization: `BoostPro Computing`_
|
||||
:date: $Date: 2005/07/17 19:53:01 $
|
||||
|
||||
:copyright: Copyright David Abrahams, Daniel Wallin
|
||||
2005. Distributed under the Boost Software License,
|
||||
2005-2009. Distributed under 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)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
__ ../../../../index.htm
|
||||
|
||||
.. _`Boost Consulting`: http://www.boost-consulting.com
|
||||
.. _`BoostPro Computing`: http://www.boostpro.com
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -174,7 +174,7 @@ Concepts
|
||||
|
||||
This section describes the generic type concepts_ used by the Parameter library.
|
||||
|
||||
.. _concepts: ../../../../more/generic_programming.html#concept
|
||||
.. _concepts: http://www.boost.org/more/generic_programming.html#concept
|
||||
|
||||
|ArgumentPack|
|
||||
--------------
|
||||
@@ -803,8 +803,8 @@ Expands to:
|
||||
return ##\ *tag-name*;
|
||||
}
|
||||
|
||||
typedef *implementation defined* _;
|
||||
typedef *implementation defined* _1;
|
||||
typedef *unspecified* _;
|
||||
typedef *unspecified* _1;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -824,8 +824,8 @@ Expands to:
|
||||
return ##\ *name*;
|
||||
}
|
||||
|
||||
typedef *implementation defined* _;
|
||||
typedef *implementation defined* _1;
|
||||
typedef *unspecified* _;
|
||||
typedef *unspecified* _1;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -970,7 +970,7 @@ already ``#defined``.
|
||||
|
||||
__ ../../../../boost/parameter/config.hpp
|
||||
|
||||
:Default Value: ``5``
|
||||
:Default Value: ``8``
|
||||
|
||||
Tutorial
|
||||
========
|
||||
|
||||
2
include/boost/parameter.hpp
Executable file → Normal file
2
include/boost/parameter.hpp
Executable file → Normal file
@@ -3,6 +3,8 @@
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See www.boost.org/libs/parameter for documentation.
|
||||
|
||||
#ifndef BOOST_PARAMETER_050401_HPP
|
||||
#define BOOST_PARAMETER_050401_HPP
|
||||
|
||||
|
||||
68
include/boost/parameter/aux_/arg_list.hpp
Executable file → Normal file
68
include/boost/parameter/aux_/arg_list.hpp
Executable file → Normal file
@@ -11,6 +11,7 @@
|
||||
#include <boost/parameter/aux_/default.hpp>
|
||||
#include <boost/parameter/aux_/parameter_requirements.hpp>
|
||||
#include <boost/parameter/aux_/yesno.hpp>
|
||||
#include <boost/parameter/aux_/is_maybe.hpp>
|
||||
#include <boost/parameter/config.hpp>
|
||||
|
||||
#include <boost/mpl/apply.hpp>
|
||||
@@ -21,11 +22,11 @@
|
||||
|
||||
#include <boost/type_traits/add_reference.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/facilities/intercept.hpp>
|
||||
|
||||
namespace boost { namespace parameter {
|
||||
namespace boost { namespace parameter {
|
||||
|
||||
// Forward declaration for aux::arg_list, below.
|
||||
template<class T> struct keyword;
|
||||
@@ -45,7 +46,7 @@ struct lambda_tag;
|
||||
// declarations to build member function overload sets that can
|
||||
// match against keywords.
|
||||
//
|
||||
|
||||
|
||||
// MPL sequence support
|
||||
struct arg_list_tag;
|
||||
|
||||
@@ -77,19 +78,15 @@ struct empty_arg_list
|
||||
};
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
// Terminator for has_key, indicating that the keyword is unique
|
||||
template <class KW>
|
||||
static no_tag has_key(KW*);
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| (BOOST_WORKAROUND(__GNUC__, < 3)) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
// The overload set technique doesn't work with these older
|
||||
// compilers, so they need some explicit handholding.
|
||||
|
||||
|
||||
// A metafunction class that, given a keyword, returns the type
|
||||
// of the base sublist whose get() function can produce the
|
||||
// value for that key
|
||||
@@ -149,24 +146,10 @@ struct empty_arg_list
|
||||
typedef arg_list_tag tag; // For dispatching to sequence intrinsics
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
template<class KW>
|
||||
no_tag operator*(empty_arg_list, KW*);
|
||||
#endif
|
||||
|
||||
// Forward declaration for arg_list::operator,
|
||||
template <class KW, class T>
|
||||
struct tagged_argument;
|
||||
|
||||
// Forward declaration for arg_list::operator[], with
|
||||
// IS_XXX helper
|
||||
struct maybe_base;
|
||||
|
||||
template <class T>
|
||||
struct is_maybe
|
||||
: is_base_and_derived<maybe_base, T>
|
||||
{};
|
||||
|
||||
template <class T>
|
||||
struct get_reference
|
||||
{
|
||||
@@ -214,9 +197,9 @@ struct arg_list : Next
|
||||
// Create a new list by prepending arg to a copy of tail. Used
|
||||
// when incrementally building this structure with the comma
|
||||
// operator.
|
||||
arg_list(TaggedArg arg, Next const& tail)
|
||||
arg_list(TaggedArg head, Next const& tail)
|
||||
: Next(tail)
|
||||
, arg(arg)
|
||||
, arg(head)
|
||||
{}
|
||||
|
||||
// A metafunction class that, given a keyword and a default
|
||||
@@ -235,32 +218,24 @@ struct arg_list : Next
|
||||
};
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && !BOOST_WORKAROUND(__GNUC__, == 2)
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
friend yes_tag operator*(arg_list, key_type*);
|
||||
# define BOOST_PARAMETER_CALL_HAS_KEY(next, key) (*(next*)0 * (key*)0)
|
||||
# else
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
// Overload for key_type, so the assert below will fire if the
|
||||
// same keyword is used again
|
||||
static yes_tag has_key(key_type*);
|
||||
using Next::has_key;
|
||||
|
||||
# define BOOST_PARAMETER_CALL_HAS_KEY(next, key) next::has_key((key*)0)
|
||||
# endif
|
||||
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
sizeof(BOOST_PARAMETER_CALL_HAS_KEY(Next,key_type)) == sizeof(no_tag)
|
||||
sizeof(Next::has_key((key_type*)0)) == sizeof(no_tag)
|
||||
, duplicate_keyword, (key_type)
|
||||
);
|
||||
|
||||
# undef BOOST_PARAMETER_CALL_HAS_KEY
|
||||
#endif
|
||||
//
|
||||
// Begin implementation of indexing operators for looking up
|
||||
// specific arguments by name
|
||||
//
|
||||
|
||||
// Helpers that handle the case when TaggedArg is
|
||||
// Helpers that handle the case when TaggedArg is
|
||||
// empty<T>.
|
||||
template <class D>
|
||||
reference get_default(D const&, mpl::false_) const
|
||||
@@ -274,9 +249,7 @@ struct arg_list : Next
|
||||
return arg.value ? arg.value.get() : arg.value.construct(d.value);
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| BOOST_WORKAROUND(__GNUC__, < 3) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
// These older compilers don't support the overload set creation
|
||||
// idiom well, so we need to do all the return type calculation
|
||||
// for the compiler and dispatch through an outer function template
|
||||
@@ -340,7 +313,7 @@ struct arg_list : Next
|
||||
template <class Default>
|
||||
reference get(default_<key_type,Default> const& d) const
|
||||
{
|
||||
return get_default(d, holds_maybe());
|
||||
return get_default(d, holds_maybe());
|
||||
}
|
||||
|
||||
template <class Default>
|
||||
@@ -348,7 +321,7 @@ struct arg_list : Next
|
||||
{
|
||||
return arg.value;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
reference operator[](keyword<key_type> const&) const
|
||||
@@ -366,6 +339,7 @@ struct arg_list : Next
|
||||
template <class Default>
|
||||
reference operator[](lazy_default<key_type, Default>) const
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((holds_maybe));
|
||||
return arg.value;
|
||||
}
|
||||
|
||||
@@ -403,7 +377,7 @@ struct arg_list : Next
|
||||
// Comma operator to compose argument list without using parameters<>.
|
||||
// Useful for argument lists with undetermined length.
|
||||
template <class KW, class T2>
|
||||
arg_list<tagged_argument<KW, T2>, self>
|
||||
arg_list<tagged_argument<KW, T2>, self>
|
||||
operator,(tagged_argument<KW,T2> x) const
|
||||
{
|
||||
return arg_list<tagged_argument<KW,T2>, self>(x, *this);
|
||||
@@ -415,10 +389,6 @@ struct arg_list : Next
|
||||
typedef arg_list_tag tag; // For dispatching to sequence intrinsics
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // ETI workaround
|
||||
template <> struct arg_list<int,int> {};
|
||||
#endif
|
||||
|
||||
// MPL sequence support
|
||||
template <class ArgumentPack>
|
||||
struct arg_list_iterator
|
||||
@@ -427,7 +397,7 @@ struct arg_list_iterator
|
||||
|
||||
// The incremented iterator
|
||||
typedef arg_list_iterator<typename ArgumentPack::tail_type> next;
|
||||
|
||||
|
||||
// dereferencing yields the key type
|
||||
typedef typename ArgumentPack::key_type type;
|
||||
};
|
||||
|
||||
52
include/boost/parameter/aux_/cast.hpp
Executable file → Normal file
52
include/boost/parameter/aux_/cast.hpp
Executable file → Normal file
@@ -5,8 +5,9 @@
|
||||
#ifndef BOOST_PARAMETER_CAST_060902_HPP
|
||||
# define BOOST_PARAMETER_CAST_060902_HPP
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
&& !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/type_traits/remove_const.hpp>
|
||||
# endif
|
||||
@@ -15,8 +16,7 @@ namespace boost { namespace parameter { namespace aux {
|
||||
|
||||
struct use_default_tag {};
|
||||
|
||||
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) value
|
||||
|
||||
@@ -38,11 +38,11 @@ struct use_default_tag {};
|
||||
// X(something, *(predicate))
|
||||
// X(something, (int))
|
||||
|
||||
template <class T>
|
||||
template <class T, class Args>
|
||||
struct cast;
|
||||
|
||||
template <>
|
||||
struct cast<void*>
|
||||
template <class Args>
|
||||
struct cast<void*, Args>
|
||||
{
|
||||
static use_default_tag execute(use_default_tag)
|
||||
{
|
||||
@@ -71,27 +71,39 @@ struct cast<void*>
|
||||
|
||||
typedef void* voidstar;
|
||||
|
||||
template <class T>
|
||||
struct cast<voidstar(T)>
|
||||
: cast<void*>
|
||||
template <class T, class Args>
|
||||
struct cast<voidstar(T), Args>
|
||||
: cast<void*, Args>
|
||||
{
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template <class T>
|
||||
struct cast<void*(T)>
|
||||
: cast<void*>
|
||||
template <class T, class Args>
|
||||
struct cast<void*(T), Args>
|
||||
: cast<void*, Args>
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
struct cast<void(T)>
|
||||
// This is a hack used in cast<> to turn the user supplied type,
|
||||
// which may or may not be a placeholder expression into one, so
|
||||
// that it will be properly evaluated by mpl::apply.
|
||||
template <class T, class Dummy = mpl::_1>
|
||||
struct as_placeholder_expr
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T, class Args>
|
||||
struct cast<void(T), Args>
|
||||
{
|
||||
typedef typename mpl::apply2<
|
||||
as_placeholder_expr<T>, Args, Args>::type type0;
|
||||
|
||||
typedef typename boost::add_reference<
|
||||
typename boost::remove_const<T>::type
|
||||
typename boost::remove_const<type0>::type
|
||||
>::type reference;
|
||||
|
||||
static use_default_tag execute(use_default_tag)
|
||||
@@ -104,7 +116,7 @@ struct cast<void(T)>
|
||||
return use_default_tag();
|
||||
}
|
||||
|
||||
static T execute(T value)
|
||||
static type0 execute(type0 value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@@ -116,9 +128,9 @@ struct cast<void(T)>
|
||||
}
|
||||
};
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) \
|
||||
boost::parameter::aux::cast<void predicate>::remove_const( \
|
||||
boost::parameter::aux::cast<void predicate>::execute(value) \
|
||||
# define BOOST_PARAMETER_FUNCTION_CAST(value, predicate, args) \
|
||||
boost::parameter::aux::cast<void predicate, args>::remove_const( \
|
||||
boost::parameter::aux::cast<void predicate, args>::execute(value) \
|
||||
)
|
||||
|
||||
# endif
|
||||
|
||||
14
include/boost/parameter/aux_/default.hpp
Executable file → Normal file
14
include/boost/parameter/aux_/default.hpp
Executable file → Normal file
@@ -4,7 +4,9 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef DEFAULT_050329_HPP
|
||||
#define DEFAULT_050329_HPP
|
||||
# define DEFAULT_050329_HPP
|
||||
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace parameter { namespace aux {
|
||||
|
||||
@@ -27,7 +29,7 @@ struct default_
|
||||
// the user when resolving the value of the parameter with the
|
||||
// given keyword
|
||||
//
|
||||
#if BOOST_WORKAROUND(__EDG_VERSION__, <= 300)
|
||||
# if BOOST_WORKAROUND(__EDG_VERSION__, <= 300)
|
||||
// These compilers need a little extra help with overload
|
||||
// resolution; we have empty_arg_list's operator[] accept a base
|
||||
// class to make that overload less preferable.
|
||||
@@ -48,8 +50,8 @@ struct lazy_default
|
||||
: lazy_default_base<KW,DefaultComputer>(x)
|
||||
{}
|
||||
};
|
||||
# define BOOST_PARAMETER_lazy_default_fallback lazy_default_base
|
||||
#else
|
||||
# define BOOST_PARAMETER_lazy_default_fallback lazy_default_base
|
||||
# else
|
||||
template <class KW, class DefaultComputer>
|
||||
struct lazy_default
|
||||
{
|
||||
@@ -58,8 +60,8 @@ struct lazy_default
|
||||
{}
|
||||
DefaultComputer const& compute_default;
|
||||
};
|
||||
# define BOOST_PARAMETER_lazy_default_fallback lazy_default
|
||||
#endif
|
||||
# define BOOST_PARAMETER_lazy_default_fallback lazy_default
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::parameter::aux
|
||||
|
||||
|
||||
26
include/boost/parameter/aux_/is_maybe.hpp
Normal file
26
include/boost/parameter/aux_/is_maybe.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright Daniel Wallin, David Abrahams 2010. 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)
|
||||
|
||||
#ifndef BOOST_PARAMETER_IS_MAYBE_050329_HPP
|
||||
#define BOOST_PARAMETER_IS_MAYBE_050329_HPP
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace parameter {
|
||||
namespace aux {
|
||||
|
||||
struct maybe_base {};
|
||||
|
||||
template <class T>
|
||||
struct is_maybe
|
||||
: is_base_and_derived<maybe_base, T>
|
||||
{};
|
||||
|
||||
} // namespace aux
|
||||
} // namespace parameter
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_PARAMETER_IS_MAYBE_050329_HPP
|
||||
60
include/boost/parameter/aux_/maybe.hpp
Executable file → Normal file
60
include/boost/parameter/aux_/maybe.hpp
Executable file → Normal file
@@ -2,21 +2,41 @@
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_PARAMETER_MAYBE_060211_HPP
|
||||
# define BOOST_PARAMETER_MAYBE_060211_HPP
|
||||
//
|
||||
// 2009.10.21 TDS remove depenency on boost::python::detail::referent_storage
|
||||
//
|
||||
#ifndef BOOST_PARAMETER_MAYBE_091021_HPP
|
||||
# define BOOST_PARAMETER_MAYBE_091021_HPP
|
||||
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/identity.hpp>
|
||||
# include <boost/type_traits/is_reference.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/optional.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/aligned_storage.hpp>
|
||||
# include <boost/type_traits/remove_cv.hpp>
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
# include <boost/parameter/aux_/is_maybe.hpp>
|
||||
|
||||
namespace boost { namespace parameter { namespace aux {
|
||||
|
||||
struct maybe_base {};
|
||||
template <class T> struct referent_size;
|
||||
|
||||
template <class T>
|
||||
struct referent_size<T&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(T));
|
||||
};
|
||||
|
||||
// A metafunction returning a POD type which can store U, where T ==
|
||||
// U&. If T is not a reference type, returns a POD which can store T.
|
||||
template <class T>
|
||||
struct referent_storage
|
||||
{
|
||||
typedef typename boost::aligned_storage<
|
||||
referent_size<T>::value
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct maybe : maybe_base
|
||||
@@ -24,17 +44,17 @@ struct maybe : maybe_base
|
||||
typedef typename add_reference<
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
T const
|
||||
# else
|
||||
# else
|
||||
typename add_const<T>::type
|
||||
# endif
|
||||
# endif
|
||||
>::type reference;
|
||||
|
||||
|
||||
typedef typename remove_cv<
|
||||
BOOST_DEDUCED_TYPENAME remove_reference<reference>::type
|
||||
>::type non_cv_value;
|
||||
|
||||
explicit maybe(T value)
|
||||
: value(value)
|
||||
|
||||
explicit maybe(T value_)
|
||||
: value(value_)
|
||||
, constructed(false)
|
||||
{}
|
||||
|
||||
@@ -48,28 +68,28 @@ struct maybe : maybe_base
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
reference construct(reference value) const
|
||||
reference construct(reference value_) const
|
||||
{
|
||||
return value;
|
||||
return value_;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
reference construct2(U const& value) const
|
||||
reference construct2(U const& value_) const
|
||||
{
|
||||
new (m_storage.bytes) non_cv_value(value);
|
||||
new (m_storage.address()) non_cv_value(value_);
|
||||
constructed = true;
|
||||
return *(non_cv_value*)m_storage.bytes;
|
||||
return *(non_cv_value*)m_storage.address();
|
||||
}
|
||||
|
||||
template <class U>
|
||||
reference construct(U const& value) const
|
||||
reference construct(U const& value_) const
|
||||
{
|
||||
return this->construct2(value);
|
||||
return this->construct2(value_);
|
||||
}
|
||||
|
||||
void destroy()
|
||||
{
|
||||
((non_cv_value*)m_storage.bytes)->~non_cv_value();
|
||||
((non_cv_value*)m_storage.address())->~non_cv_value();
|
||||
}
|
||||
|
||||
typedef reference(maybe<T>::*safe_bool)() const;
|
||||
@@ -87,7 +107,9 @@ struct maybe : maybe_base
|
||||
private:
|
||||
boost::optional<T> value;
|
||||
mutable bool constructed;
|
||||
mutable typename boost::python::detail::referent_storage<
|
||||
|
||||
|
||||
mutable typename referent_storage<
|
||||
reference
|
||||
>::type m_storage;
|
||||
};
|
||||
|
||||
0
include/boost/parameter/aux_/overloads.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/overloads.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/parameter_requirements.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/parameter_requirements.hpp
Executable file → Normal file
84
include/boost/parameter/aux_/parenthesized_type.hpp
Executable file → Normal file
84
include/boost/parameter/aux_/parenthesized_type.hpp
Executable file → Normal file
@@ -18,96 +18,12 @@ namespace boost { namespace parameter { namespace aux {
|
||||
template <class UnaryFunctionPointer>
|
||||
struct unaryfunptr_arg_type;
|
||||
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
|
||||
template <class Arg>
|
||||
struct unaryfunptr_arg_type<void(*)(Arg)>
|
||||
{
|
||||
typedef Arg type;
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
// Use the "native typeof" bugfeatures of older versions of MSVC to
|
||||
// accomplish what we'd normally do with partial specialization. This
|
||||
// capability was discovered by Igor Chesnokov.
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, != 1300)
|
||||
|
||||
// This version applies to VC6.5 and VC7.1 (except that we can just
|
||||
// use partial specialization for the latter in this case).
|
||||
|
||||
// This gets used as a base class.
|
||||
template<typename Address>
|
||||
struct msvc_type_memory
|
||||
{
|
||||
// A nullary metafunction that will yield the Value type "stored"
|
||||
// at this Address.
|
||||
struct storage;
|
||||
};
|
||||
|
||||
template<typename Value, typename Address>
|
||||
struct msvc_store_type : msvc_type_memory<Address>
|
||||
{
|
||||
// VC++ somehow lets us define the base's nested storage
|
||||
// metafunction here, where we have the Value type we'd like to
|
||||
// "store" in it. Later we can come back to the base class and
|
||||
// extract the "stored type."
|
||||
typedef msvc_type_memory<Address> location;
|
||||
struct location::storage
|
||||
{
|
||||
typedef Value type;
|
||||
};
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
// This slightly more complicated version of the same thing is
|
||||
// required for msvc-7.0
|
||||
template<typename Address>
|
||||
struct msvc_type_memory
|
||||
{
|
||||
template<bool>
|
||||
struct storage_impl;
|
||||
|
||||
typedef storage_impl<true> storage;
|
||||
};
|
||||
|
||||
template<typename Value, typename Address>
|
||||
struct msvc_store_type : msvc_type_memory<Address>
|
||||
{
|
||||
// Rather than supplying a definition for the base class' nested
|
||||
// class, we specialize the base class' nested template
|
||||
template<>
|
||||
struct storage_impl<true>
|
||||
{
|
||||
typedef Value type;
|
||||
};
|
||||
};
|
||||
|
||||
# endif
|
||||
|
||||
// Function template argument deduction does many of the same things
|
||||
// as type matching during partial specialization, so we call a
|
||||
// function template to "store" T into the type memory addressed by
|
||||
// void(*)(T).
|
||||
template <class T>
|
||||
msvc_store_type<T,void(*)(T)>
|
||||
msvc_store_argument_type(void(*)(T));
|
||||
|
||||
template <class FunctionPointer>
|
||||
struct unaryfunptr_arg_type
|
||||
{
|
||||
// We don't want the function to be evaluated, just instantiated,
|
||||
// so protect it inside of sizeof.
|
||||
enum { dummy = sizeof(msvc_store_argument_type((FunctionPointer)0)) };
|
||||
|
||||
// Now pull the type out of the instantiated base class
|
||||
typedef typename msvc_type_memory<FunctionPointer>::storage::type type;
|
||||
};
|
||||
|
||||
# endif
|
||||
|
||||
template <>
|
||||
struct unaryfunptr_arg_type<void(*)(void)>
|
||||
{
|
||||
|
||||
0
include/boost/parameter/aux_/preprocessor/flatten.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/preprocessor/flatten.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/preprocessor/for_each.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/preprocessor/for_each.hpp
Executable file → Normal file
@@ -1,131 +0,0 @@
|
||||
// Copyright Daniel Wallin 2005. 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)
|
||||
|
||||
#ifndef BOOST_PARAMETER_INVOKER_051210_HPP
|
||||
# define BOOST_PARAMETER_INVOKER_051210_HPP
|
||||
|
||||
# include <boost/mpl/begin.hpp>
|
||||
# include <boost/mpl/next.hpp>
|
||||
# include <boost/mpl/deref.hpp>
|
||||
# include <boost/parameter/keyword.hpp>
|
||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||
|
||||
namespace boost { namespace parameter { namespace python { namespace aux {
|
||||
|
||||
template <long Arity, class M, class R, class Args>
|
||||
struct invoker;
|
||||
|
||||
template <class M, class R>
|
||||
struct make_invoker
|
||||
{
|
||||
template <class Args>
|
||||
struct apply
|
||||
{
|
||||
typedef invoker<
|
||||
mpl::size<Args>::value, M, R, Args
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
template <long Arity, class M, class R, class T, class Args>
|
||||
struct member_invoker;
|
||||
|
||||
template <class M, class R, class T>
|
||||
struct make_member_invoker
|
||||
{
|
||||
template <class Args>
|
||||
struct apply
|
||||
{
|
||||
typedef member_invoker<
|
||||
mpl::size<Args>::value, M, R, T, Args
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
template <long Arity, class T, class R, class Args>
|
||||
struct call_invoker;
|
||||
|
||||
template <class T, class R>
|
||||
struct make_call_invoker
|
||||
{
|
||||
template <class Args>
|
||||
struct apply
|
||||
{
|
||||
typedef call_invoker<
|
||||
mpl::size<Args>::value, T, R, Args
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
template <long Arity, class T, class Args>
|
||||
struct init_invoker;
|
||||
|
||||
template <class T>
|
||||
struct make_init_invoker
|
||||
{
|
||||
template <class Args>
|
||||
struct apply
|
||||
{
|
||||
typedef init_invoker<
|
||||
mpl::size<Args>::value, T, Args
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
template <class M, class R, class Args>
|
||||
struct invoker<0, M, R, Args>
|
||||
{
|
||||
static R execute()
|
||||
{
|
||||
return M()(boost::type<R>());
|
||||
}
|
||||
};
|
||||
|
||||
template <class M, class R, class T, class Args>
|
||||
struct member_invoker<0, M, R, T, Args>
|
||||
{
|
||||
static R execute(T& self)
|
||||
{
|
||||
return M()(boost::type<R>(), self);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class R, class Args>
|
||||
struct call_invoker<0, T, R, Args>
|
||||
{
|
||||
static R execute(T& self)
|
||||
{
|
||||
return self();
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class Args>
|
||||
struct init_invoker<0, T, Args>
|
||||
{
|
||||
static T* execute(T& self)
|
||||
{
|
||||
return new T;
|
||||
}
|
||||
};
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, \
|
||||
(1, BOOST_PARAMETER_MAX_ARITY, <boost/parameter/aux_/python/invoker_iterate.hpp>, 1))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, \
|
||||
(1, BOOST_PARAMETER_MAX_ARITY, <boost/parameter/aux_/python/invoker_iterate.hpp>, 2))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, \
|
||||
(1, BOOST_PARAMETER_MAX_ARITY, <boost/parameter/aux_/python/invoker_iterate.hpp>, 3))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, \
|
||||
(1, BOOST_PARAMETER_MAX_ARITY, <boost/parameter/aux_/python/invoker_iterate.hpp>, 4))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
}}}} // namespace boost::parameter::python::aux
|
||||
|
||||
#endif // BOOST_PARAMETER_INVOKER_051210_HPP
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
// Copyright Daniel Wallin 2005. 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)
|
||||
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/dec.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
|
||||
#define N BOOST_PP_ITERATION()
|
||||
|
||||
#define BOOST_PARAMETER_PY_ARG_TYPES(z, n, _) \
|
||||
typedef typename mpl::next< \
|
||||
BOOST_PP_CAT(iter,BOOST_PP_DEC(n)) \
|
||||
>::type BOOST_PP_CAT(iter,n); \
|
||||
\
|
||||
typedef typename mpl::deref<BOOST_PP_CAT(iter,n)>::type BOOST_PP_CAT(spec,n); \
|
||||
typedef typename mpl::if_< \
|
||||
mpl::and_< \
|
||||
mpl::not_<typename BOOST_PP_CAT(spec,n)::required> \
|
||||
, typename BOOST_PP_CAT(spec,n)::optimized_default \
|
||||
> \
|
||||
, parameter::aux::maybe<typename BOOST_PP_CAT(spec,n)::type> \
|
||||
, typename BOOST_PP_CAT(spec,n)::type \
|
||||
>::type BOOST_PP_CAT(arg,n); \
|
||||
typedef typename BOOST_PP_CAT(spec,n)::keyword BOOST_PP_CAT(kw,n);
|
||||
|
||||
#if BOOST_PP_ITERATION_FLAGS() == 1
|
||||
template <class M, class R, class Args>
|
||||
struct invoker<N, M, R, Args>
|
||||
#elif BOOST_PP_ITERATION_FLAGS() == 2
|
||||
template <class T, class R, class Args>
|
||||
struct call_invoker<N, T, R, Args>
|
||||
#elif BOOST_PP_ITERATION_FLAGS() == 3
|
||||
template <class T, class Args>
|
||||
struct init_invoker<N, T, Args>
|
||||
#elif BOOST_PP_ITERATION_FLAGS() == 4
|
||||
template <class M, class R, class T, class Args>
|
||||
struct member_invoker<N, M, R, T, Args>
|
||||
#endif
|
||||
{
|
||||
typedef typename mpl::begin<Args>::type iter0;
|
||||
typedef typename mpl::deref<iter0>::type spec0;
|
||||
typedef typename mpl::if_<
|
||||
mpl::and_<
|
||||
mpl::not_<typename spec0::required>
|
||||
, typename spec0::optimized_default
|
||||
>
|
||||
, parameter::aux::maybe<typename spec0::type>
|
||||
, typename spec0::type
|
||||
>::type arg0;
|
||||
typedef typename spec0::keyword kw0;
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(1, N, BOOST_PARAMETER_PY_ARG_TYPES, ~)
|
||||
|
||||
static
|
||||
#if BOOST_PP_ITERATION_FLAGS() == 3
|
||||
T*
|
||||
#else
|
||||
R
|
||||
#endif
|
||||
execute(
|
||||
#if BOOST_PP_ITERATION_FLAGS() == 2 || BOOST_PP_ITERATION_FLAGS() == 4
|
||||
T& self
|
||||
,
|
||||
#endif
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(N, arg, a)
|
||||
)
|
||||
{
|
||||
return
|
||||
#if BOOST_PP_ITERATION_FLAGS() == 1 || BOOST_PP_ITERATION_FLAGS() == 4
|
||||
M()(
|
||||
boost::type<R>()
|
||||
# if BOOST_PP_ITERATION_FLAGS() == 4
|
||||
, self
|
||||
# endif
|
||||
, BOOST_PP_ENUM_BINARY_PARAMS(N, parameter::keyword<kw, >::get() = a)
|
||||
);
|
||||
#elif BOOST_PP_ITERATION_FLAGS() == 2
|
||||
self(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(N, parameter::keyword<kw, >::get() = a)
|
||||
);
|
||||
#elif BOOST_PP_ITERATION_FLAGS() == 3
|
||||
new T(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(N, parameter::keyword<kw, >::get() = a)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#undef BOOST_PARAMETER_PY_ARG_TYPES
|
||||
#undef N
|
||||
|
||||
0
include/boost/parameter/aux_/result_of0.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/result_of0.hpp
Executable file → Normal file
5
include/boost/parameter/aux_/set.hpp
Executable file → Normal file
5
include/boost/parameter/aux_/set.hpp
Executable file → Normal file
@@ -5,8 +5,9 @@
|
||||
#ifndef BOOST_PARAMETER_SET_060912_HPP
|
||||
# define BOOST_PARAMETER_SET_060912_HPP
|
||||
|
||||
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) \
|
||||
&& !BOOST_WORKAROUND(__GNUC__, < 3)
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# include <boost/mpl/insert.hpp>
|
||||
# include <boost/mpl/set/set0.hpp>
|
||||
# include <boost/mpl/has_key.hpp>
|
||||
|
||||
0
include/boost/parameter/aux_/tag.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/tag.hpp
Executable file → Normal file
5
include/boost/parameter/aux_/tagged_argument.hpp
Executable file → Normal file
5
include/boost/parameter/aux_/tagged_argument.hpp
Executable file → Normal file
@@ -14,6 +14,7 @@
|
||||
# include <boost/mpl/and.hpp>
|
||||
# include <boost/mpl/not.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_reference.hpp>
|
||||
|
||||
namespace boost { namespace parameter { namespace aux {
|
||||
@@ -119,13 +120,13 @@ struct tagged_argument : tagged_argument_base
|
||||
}
|
||||
# else
|
||||
template <class Default>
|
||||
reference operator[](default_<key_type,Default> const& x) const
|
||||
reference operator[](default_<key_type,Default> const& ) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
template <class F>
|
||||
reference operator[](lazy_default<key_type,F> const& x) const
|
||||
reference operator[](lazy_default<key_type,F> const& ) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
0
include/boost/parameter/aux_/template_keyword.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/template_keyword.hpp
Executable file → Normal file
6
include/boost/parameter/aux_/unwrap_cv_reference.hpp
Executable file → Normal file
6
include/boost/parameter/aux_/unwrap_cv_reference.hpp
Executable file → Normal file
@@ -44,12 +44,6 @@ struct is_cv_reference_wrapper
|
||||
value> type;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(MSVC, == 1200)
|
||||
template <>
|
||||
struct is_cv_reference_wrapper<int>
|
||||
: mpl::false_ {};
|
||||
#endif
|
||||
|
||||
// Needed for unwrap_cv_reference below. T might be const, so
|
||||
// eval_if might fail because of deriving from T const on EDG.
|
||||
template <class T>
|
||||
|
||||
0
include/boost/parameter/aux_/void.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/void.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/yesno.hpp
Executable file → Normal file
0
include/boost/parameter/aux_/yesno.hpp
Executable file → Normal file
30
include/boost/parameter/binding.hpp
Executable file → Normal file
30
include/boost/parameter/binding.hpp
Executable file → Normal file
@@ -11,18 +11,13 @@
|
||||
# include <boost/parameter/aux_/void.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
# include <boost/mpl/eval_if.hpp>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace parameter {
|
||||
|
||||
// A metafunction that, given an argument pack, returns the type of
|
||||
// the parameter identified by the given keyword. If no such
|
||||
// parameter has been specified, returns Default
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
template <class Parameters, class Keyword, class Default>
|
||||
struct binding0
|
||||
{
|
||||
@@ -40,14 +35,9 @@ struct binding0
|
||||
# endif
|
||||
|
||||
template <class Parameters, class Keyword, class Default = void_>
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
struct binding
|
||||
# else
|
||||
struct binding_eti
|
||||
# endif
|
||||
{
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
typedef typename mpl::eval_if<
|
||||
mpl::is_placeholder<Parameters>
|
||||
, mpl::identity<int>
|
||||
@@ -66,24 +56,8 @@ struct binding_eti
|
||||
));
|
||||
# endif
|
||||
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,binding,(Parameters,Keyword,Default))
|
||||
# endif
|
||||
};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
template <class Parameters, class Keyword, class Default = void_>
|
||||
struct binding
|
||||
{
|
||||
typedef typename mpl::eval_if<
|
||||
is_same<Parameters, int>
|
||||
, mpl::identity<int>
|
||||
, binding_eti<Parameters, Keyword, Default>
|
||||
>::type type;
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,binding,(Parameters,Keyword,Default))
|
||||
};
|
||||
# endif
|
||||
|
||||
// A metafunction that, given an argument pack, returns the type of
|
||||
// the parameter identified by the given keyword. If no such
|
||||
|
||||
2
include/boost/parameter/config.hpp
Executable file → Normal file
2
include/boost/parameter/config.hpp
Executable file → Normal file
@@ -7,7 +7,7 @@
|
||||
#define BOOST_PARAMETER_CONFIG_050403_HPP
|
||||
|
||||
#ifndef BOOST_PARAMETER_MAX_ARITY
|
||||
# define BOOST_PARAMETER_MAX_ARITY 5
|
||||
# define BOOST_PARAMETER_MAX_ARITY 8
|
||||
#endif
|
||||
|
||||
#endif // BOOST_PARAMETER_CONFIG_050403_HPP
|
||||
|
||||
30
include/boost/parameter/keyword.hpp
Executable file → Normal file
30
include/boost/parameter/keyword.hpp
Executable file → Normal file
@@ -52,7 +52,6 @@ struct keyword
|
||||
return aux::lazy_default<Tag, Default>(default_);
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
|
||||
template <class T>
|
||||
typename aux::tag<Tag, T const>::type const
|
||||
operator=(T const& x) const
|
||||
@@ -60,15 +59,10 @@ struct keyword
|
||||
typedef typename aux::tag<Tag, T const>::type result;
|
||||
return result(x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) // avoid partial ordering bugs
|
||||
template <class Default>
|
||||
aux::default_<Tag, const Default>
|
||||
operator|(const Default& default_) const
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
||||
volatile
|
||||
#endif
|
||||
{
|
||||
return aux::default_<Tag, const Default>(default_);
|
||||
}
|
||||
@@ -76,13 +70,9 @@ struct keyword
|
||||
template <class Default>
|
||||
aux::lazy_default<Tag, Default>
|
||||
operator||(Default const& default_) const
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
||||
volatile
|
||||
#endif
|
||||
{
|
||||
return aux::lazy_default<Tag, Default>(default_);
|
||||
}
|
||||
#endif
|
||||
|
||||
public: // Insurance against ODR violations
|
||||
|
||||
@@ -109,24 +99,6 @@ keyword<Tag> const keyword<Tag>::instance = {};
|
||||
// reference in an anonymous namespace to a singleton instance of that
|
||||
// type.
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
|
||||
# define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
|
||||
namespace tag_namespace \
|
||||
{ \
|
||||
struct name \
|
||||
{ \
|
||||
static char const* keyword_name() \
|
||||
{ \
|
||||
return #name; \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
static ::boost::parameter::keyword<tag_namespace::name> const& name \
|
||||
= ::boost::parameter::keyword<tag_namespace::name>::instance;
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_PARAMETER_KEYWORD(tag_namespace,name) \
|
||||
namespace tag_namespace \
|
||||
{ \
|
||||
@@ -144,8 +116,6 @@ keyword<Tag> const keyword<Tag>::instance = {};
|
||||
= ::boost::parameter::keyword<tag_namespace::name>::instance;\
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}} // namespace boost::parameter
|
||||
|
||||
#endif // KEYWORD_050328_HPP
|
||||
|
||||
3
include/boost/parameter/macros.hpp
Executable file → Normal file
3
include/boost/parameter/macros.hpp
Executable file → Normal file
@@ -15,13 +15,14 @@
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#define BOOST_PARAMETER_FUN_TEMPLATE_HEAD1(n) \
|
||||
template<BOOST_PP_ENUM_PARAMS(n, class T)>
|
||||
|
||||
#define BOOST_PARAMETER_FUN_TEMPLATE_HEAD0(n)
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
|
||||
# define BOOST_PARAMETER_MATCH_TYPE(n, param) \
|
||||
BOOST_PP_EXPR_IF(n, typename) param::match \
|
||||
|
||||
0
include/boost/parameter/match.hpp
Executable file → Normal file
0
include/boost/parameter/match.hpp
Executable file → Normal file
25
include/boost/parameter/name.hpp
Executable file → Normal file
25
include/boost/parameter/name.hpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
# include <boost/mpl/placeholders.hpp>
|
||||
|
||||
# if !defined(BOOST_NO_SFINAE) \
|
||||
&& !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
&& !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
|
||||
# include <boost/utility/enable_if.hpp>
|
||||
# include <boost/mpl/lambda.hpp>
|
||||
@@ -26,7 +26,7 @@ namespace boost { namespace parameter { namespace aux {
|
||||
// Tag type passed to MPL lambda.
|
||||
struct lambda_tag;
|
||||
|
||||
struct name_tag_base
|
||||
struct name_tag_base
|
||||
{};
|
||||
|
||||
template <class Tag>
|
||||
@@ -45,7 +45,7 @@ namespace boost { namespace mpl {
|
||||
template <class T>
|
||||
struct lambda<
|
||||
T
|
||||
, typename enable_if<
|
||||
, typename boost::enable_if<
|
||||
parameter::aux::is_name_tag<T>, parameter::aux::lambda_tag
|
||||
>::type
|
||||
>
|
||||
@@ -74,19 +74,6 @@ struct lambda<
|
||||
# define BOOST_PARAMETER_IS_BINARY(x) BOOST_PP_IS_BINARY(x)
|
||||
# endif
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
# define BOOST_PARAMETER_NAME_OBJECT(tag, name) \
|
||||
static ::boost::parameter::keyword<tag> const& name \
|
||||
= ::boost::parameter::keyword<tag>::instance;
|
||||
# else
|
||||
# define BOOST_PARAMETER_NAME_OBJECT(tag, name) \
|
||||
namespace \
|
||||
{ \
|
||||
::boost::parameter::keyword<tag> const& name \
|
||||
= ::boost::parameter::keyword<tag>::instance; \
|
||||
}
|
||||
# endif
|
||||
|
||||
# define BOOST_PARAMETER_BASIC_NAME(tag_namespace, tag, name) \
|
||||
namespace tag_namespace \
|
||||
{ \
|
||||
@@ -106,7 +93,11 @@ struct lambda<
|
||||
> _1; \
|
||||
}; \
|
||||
} \
|
||||
BOOST_PARAMETER_NAME_OBJECT(tag_namespace::tag, name)
|
||||
namespace \
|
||||
{ \
|
||||
::boost::parameter::keyword<tag_namespace::tag> const& name \
|
||||
= ::boost::parameter::keyword<tag_namespace::tag>::instance; \
|
||||
}
|
||||
|
||||
# define BOOST_PARAMETER_COMPLEX_NAME_TUPLE1(tag,namespace) \
|
||||
(tag, namespace), ~
|
||||
|
||||
4
include/boost/parameter/parameters.hpp
Executable file → Normal file
4
include/boost/parameter/parameters.hpp
Executable file → Normal file
@@ -725,7 +725,7 @@ struct parameters
|
||||
// ::type).
|
||||
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
// If NamedList satisfies the PS0, PS1, ..., this is a
|
||||
// metafunction returning parameters. Otherwise it
|
||||
// has no nested ::type.
|
||||
@@ -775,7 +775,7 @@ struct parameters
|
||||
#endif
|
||||
>
|
||||
struct match
|
||||
# ifndef BOOST_NO_SFINAE
|
||||
# if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
: match_base<
|
||||
typename aux::make_arg_list<
|
||||
typename BOOST_PARAMETER_build_arg_list(
|
||||
|
||||
130
include/boost/parameter/preprocessor.hpp
Executable file → Normal file
130
include/boost/parameter/preprocessor.hpp
Executable file → Normal file
@@ -14,7 +14,9 @@
|
||||
# include <boost/parameter/aux_/preprocessor/flatten.hpp>
|
||||
|
||||
# include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
# include <boost/preprocessor/comparison/equal.hpp>
|
||||
# include <boost/preprocessor/control/if.hpp>
|
||||
# include <boost/preprocessor/control/iif.hpp>
|
||||
# include <boost/preprocessor/control/expr_if.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
@@ -23,22 +25,21 @@
|
||||
# include <boost/preprocessor/seq/for_each_product.hpp>
|
||||
# include <boost/preprocessor/seq/for_each_i.hpp>
|
||||
# include <boost/preprocessor/tuple/elem.hpp>
|
||||
# include <boost/preprocessor/tuple/eat.hpp>
|
||||
# include <boost/preprocessor/seq/fold_left.hpp>
|
||||
# include <boost/preprocessor/seq/push_back.hpp>
|
||||
# include <boost/preprocessor/seq/size.hpp>
|
||||
# include <boost/preprocessor/seq/enum.hpp>
|
||||
# include <boost/preprocessor/seq/push_back.hpp>
|
||||
|
||||
# include <boost/preprocessor/detail/is_nullary.hpp>
|
||||
|
||||
# include <boost/mpl/always.hpp>
|
||||
# include <boost/mpl/apply_wrap.hpp>
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
# include <boost/type.hpp>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace parameter { namespace aux {
|
||||
|
||||
# ifndef BOOST_NO_SFINAE
|
||||
# if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
|
||||
// Given Match, which is "void x" where x is an argument matching
|
||||
// criterion, extract a corresponding MPL predicate.
|
||||
@@ -97,41 +98,6 @@ struct match
|
||||
{};
|
||||
# endif
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
||||
|
||||
// Function template argument deduction does many of the same things
|
||||
// as type matching during partial specialization, so we call a
|
||||
// function template to "store" T into the type memory addressed by
|
||||
// void(*)(T).
|
||||
template <class T>
|
||||
msvc_store_type<T,void*(*)(void**(T))>
|
||||
msvc_store_predicate_type(void*(*)(void**(T)));
|
||||
|
||||
template <class T>
|
||||
msvc_store_type<boost::is_convertible<mpl::_,T>,void*(*)(void*(T))>
|
||||
msvc_store_predicate_type(void*(*)(void*(T)));
|
||||
|
||||
template <class FunctionType>
|
||||
struct unwrap_predicate
|
||||
{
|
||||
static FunctionType f;
|
||||
|
||||
// We don't want the function to be evaluated, just instantiated,
|
||||
// so protect it inside of sizeof.
|
||||
enum { dummy = sizeof(msvc_store_predicate_type(f)) };
|
||||
|
||||
// Now pull the type out of the instantiated base class
|
||||
typedef typename msvc_type_memory<FunctionType>::storage::type type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unwrap_predicate<void*(*)(void**)>
|
||||
{
|
||||
typedef mpl::always<mpl::true_> type;
|
||||
};
|
||||
|
||||
# endif
|
||||
|
||||
# undef false_
|
||||
|
||||
template <
|
||||
@@ -149,10 +115,10 @@ struct argument_pack
|
||||
, typename Parameters::deduced_list
|
||||
, tag_keyword_arg
|
||||
, mpl::false_
|
||||
>::type type;
|
||||
>::type result;
|
||||
typedef typename mpl::first<result>::type type;
|
||||
};
|
||||
|
||||
# if 1 //BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
// Works around VC6 problem where it won't accept rvalues.
|
||||
template <class T>
|
||||
T& as_lvalue(T& value, long)
|
||||
@@ -165,11 +131,9 @@ T const& as_lvalue(T const& value, int)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
# endif
|
||||
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
template <class Predicate, class T, class Args>
|
||||
struct apply_predicate
|
||||
@@ -353,11 +317,11 @@ struct funptr_predicate<void**>
|
||||
template<BOOST_PP_ENUM_PARAMS_Z(z, n, class ParameterArgumentType)>
|
||||
/**/
|
||||
|
||||
# ifndef BOOST_NO_SFINAE
|
||||
# if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
# define BOOST_PARAMETER_FUNCTION_FWD_MATCH_Z(z, name, parameters, n) \
|
||||
, typename boost::parameter::aux::match< \
|
||||
parameters, BOOST_PP_ENUM_PARAMS(n, ParameterArgumentType) \
|
||||
>::type boost_parameter_enabler_argument = parameters()
|
||||
>::type = parameters()
|
||||
# else
|
||||
# define BOOST_PARAMETER_FUNCTION_FWD_MATCH_Z(z, name, parameters, n)
|
||||
# endif
|
||||
@@ -496,13 +460,7 @@ struct funptr_predicate<void**>
|
||||
# define BOOST_PARAMETER_FUNCTION_PARAMETERS_QUALIFIER_deduced_required(tag) \
|
||||
required<boost::parameter::deduced<tag>
|
||||
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
||||
# define BOOST_PARAMETER_PREDICATE_TYPE(p) void*(*) (void* p)
|
||||
# else
|
||||
# define BOOST_PARAMETER_PREDICATE_TYPE(p) void p
|
||||
# endif
|
||||
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_PARAMETERS_M(r,tag_namespace,i,elem) \
|
||||
BOOST_PP_COMMA_IF(i) \
|
||||
@@ -515,24 +473,9 @@ struct funptr_predicate<void**>
|
||||
) \
|
||||
) \
|
||||
, typename boost::parameter::aux::unwrap_predicate< \
|
||||
BOOST_PARAMETER_PREDICATE_TYPE(BOOST_PARAMETER_FN_ARG_PRED(elem)) \
|
||||
void BOOST_PARAMETER_FN_ARG_PRED(elem) \
|
||||
>::type \
|
||||
>
|
||||
# elif BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
# define BOOST_PARAMETER_FUNCTION_PARAMETERS_M(r,tag_namespace,i,elem) \
|
||||
BOOST_PP_COMMA_IF(i) \
|
||||
boost::parameter::BOOST_PP_CAT( \
|
||||
BOOST_PARAMETER_FUNCTION_PARAMETERS_QUALIFIER_ \
|
||||
, BOOST_PARAMETER_FN_ARG_QUALIFIER(elem) \
|
||||
)( \
|
||||
tag_namespace::BOOST_PARAMETER_FUNCTION_KEYWORD( \
|
||||
BOOST_PARAMETER_FN_ARG_KEYWORD(elem) \
|
||||
) \
|
||||
) \
|
||||
, boost::parameter::aux::funptr_predicate< \
|
||||
void* BOOST_PARAMETER_FN_ARG_PRED(elem) \
|
||||
> \
|
||||
>
|
||||
# elif BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# define BOOST_PARAMETER_FUNCTION_PARAMETERS_M(r,tag_namespace,i,elem) \
|
||||
BOOST_PP_COMMA_IF(i) \
|
||||
@@ -577,21 +520,6 @@ struct funptr_predicate<void**>
|
||||
typedef typename BOOST_PARAMETER_PARENTHESIZED_TYPE(result) type; \
|
||||
};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_RESULT(result, name, args) \
|
||||
BOOST_PARAMETER_FUNCTION_RESULT_(result, name, args) \
|
||||
template <> \
|
||||
struct BOOST_PARAMETER_FUNCTION_RESULT_NAME(name)<int> \
|
||||
{ typedef int type; };
|
||||
|
||||
# else
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_RESULT(result, name, args) \
|
||||
BOOST_PARAMETER_FUNCTION_RESULT_(result, name, args)
|
||||
|
||||
# endif
|
||||
|
||||
// Defines implementation function
|
||||
# define BOOST_PARAMETER_FUNCTION_IMPL_HEAD(name) \
|
||||
template <class Args> \
|
||||
@@ -695,6 +623,7 @@ struct funptr_predicate<void**>
|
||||
) \
|
||||
] \
|
||||
, BOOST_PARAMETER_FN_ARG_PRED(arg) \
|
||||
, Args \
|
||||
)
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_DEFAULT_FUNCTION_BODY(name, n, split_args, tag_namespace) \
|
||||
@@ -722,6 +651,7 @@ struct funptr_predicate<void**>
|
||||
BOOST_PARAMETER_FUNCTION_CAST( \
|
||||
boost::parameter::aux::as_lvalue(BOOST_PARAMETER_FN_ARG_DEFAULT(arg), 0L) \
|
||||
, BOOST_PARAMETER_FN_ARG_PRED(arg) \
|
||||
, Args \
|
||||
)
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_DEFAULT_EVAL_DEFAULT_BODY(name, n, split_args, tag_ns, const_) \
|
||||
@@ -837,6 +767,7 @@ struct funptr_predicate<void**>
|
||||
boost::parameter::keyword<tag_ns::BOOST_PARAMETER_FN_ARG_KEYWORD(arg)>::instance \
|
||||
] \
|
||||
, BOOST_PARAMETER_FN_ARG_PRED(arg) \
|
||||
, Args \
|
||||
)
|
||||
|
||||
// Generates the function template that recives a ArgumentPack, and then
|
||||
@@ -887,7 +818,7 @@ struct funptr_predicate<void**>
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION_STATIC(name) \
|
||||
ResultType BOOST_PARAMETER_FUNCTION_DEFAULT_NAME(name)( \
|
||||
ResultType(*)() \
|
||||
, Args const& args \
|
||||
, Args const& \
|
||||
, int \
|
||||
BOOST_PARAMETER_FUNCTION_DEFAULT_ARGUMENTS( \
|
||||
BOOST_PARAMETER_FUNCTION_DEFAULT_FUNCTION_ARG \
|
||||
@@ -906,7 +837,7 @@ struct funptr_predicate<void**>
|
||||
|
||||
// Defines the result metafunction and the parameters specialization.
|
||||
# define BOOST_PARAMETER_FUNCTION_HEAD(result, name, tag_namespace, args) \
|
||||
BOOST_PARAMETER_FUNCTION_RESULT(result, name, args) \
|
||||
BOOST_PARAMETER_FUNCTION_RESULT_(result, name, args) \
|
||||
\
|
||||
BOOST_PARAMETER_FUNCTION_PARAMETERS(tag_namespace, name, args) \
|
||||
BOOST_PARAMETER_FUNCTION_PARAMETERS_NAME(name); \
|
||||
@@ -1012,18 +943,6 @@ struct funptr_predicate<void**>
|
||||
BOOST_PP_COMMA_IF(i) elem& BOOST_PP_CAT(a, i)
|
||||
/**/
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
|
||||
// Older MSVC can't do what's necessary to handle commas in base names; just
|
||||
// use a typedef instead if you have a base name that contains commas.
|
||||
# define BOOST_PARAMETER_PARENTHESIZED_BASE(x) BOOST_PP_SEQ_HEAD(x)
|
||||
|
||||
# else
|
||||
|
||||
# define BOOST_PARAMETER_PARENTHESIZED_BASE(x) BOOST_PARAMETER_PARENTHESIZED_TYPE(x)
|
||||
|
||||
# endif
|
||||
|
||||
# define BOOST_PARAMETER_FUNCTION_FWD_CONSTRUCTOR00(z, n, r, data, elem) \
|
||||
BOOST_PP_IF( \
|
||||
n \
|
||||
@@ -1048,7 +967,7 @@ struct funptr_predicate<void**>
|
||||
, n \
|
||||
) \
|
||||
) \
|
||||
: BOOST_PARAMETER_PARENTHESIZED_BASE(BOOST_PP_TUPLE_ELEM(6,3,data)) ( \
|
||||
: BOOST_PARAMETER_PARENTHESIZED_TYPE(BOOST_PP_TUPLE_ELEM(6,3,data)) ( \
|
||||
BOOST_PP_CAT(constructor_parameters, __LINE__)()( \
|
||||
BOOST_PP_ENUM_PARAMS_Z(z, n, a) \
|
||||
) \
|
||||
@@ -1139,18 +1058,7 @@ struct funptr_predicate<void**>
|
||||
, (const ParameterArgumentType ## i)(ParameterArgumentType ## i) \
|
||||
, (const ParameterArgumentType ## i) \
|
||||
))
|
||||
// MSVC6.5 lets us bind rvalues to T&.
|
||||
# elif BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
# define BOOST_PARAMETER_FUNCTION_FWD_COMBINATION(r, _, i, elem) \
|
||||
(BOOST_PP_IF( \
|
||||
BOOST_PARAMETER_FUNCTION_IS_KEYWORD_QUALIFIER( \
|
||||
BOOST_PARAMETER_FN_ARG_NAME(elem) \
|
||||
) \
|
||||
, (ParameterArgumentType ## i) \
|
||||
, (const ParameterArgumentType ## i) \
|
||||
))
|
||||
// No partial ordering. This feature doesn't work.
|
||||
// This is exactly the same as for VC6.5, but we might change it later.
|
||||
# else
|
||||
# define BOOST_PARAMETER_FUNCTION_FWD_COMBINATION(r, _, i, elem) \
|
||||
(BOOST_PP_IF( \
|
||||
|
||||
@@ -1,735 +0,0 @@
|
||||
// Copyright Daniel Wallin 2006. 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)
|
||||
|
||||
#ifndef BOOST_PARAMETER_PYTHON_060209_HPP
|
||||
# define BOOST_PARAMETER_PYTHON_060209_HPP
|
||||
|
||||
# include <boost/mpl/vector.hpp>
|
||||
# include <boost/mpl/fold.hpp>
|
||||
# include <boost/mpl/prior.hpp>
|
||||
# include <boost/mpl/shift_right.hpp>
|
||||
# include <boost/mpl/shift_left.hpp>
|
||||
# include <boost/mpl/bitand.hpp>
|
||||
# include <boost/mpl/pair.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
# include <boost/mpl/push_back.hpp>
|
||||
# include <boost/mpl/or.hpp>
|
||||
# include <boost/mpl/count_if.hpp>
|
||||
# include <boost/mpl/transform.hpp>
|
||||
# include <boost/mpl/front.hpp>
|
||||
# include <boost/mpl/iterator_range.hpp>
|
||||
# include <boost/mpl/next.hpp>
|
||||
# include <boost/mpl/begin_end.hpp>
|
||||
# include <boost/mpl/not.hpp>
|
||||
# include <boost/mpl/empty.hpp>
|
||||
# include <boost/python/def.hpp>
|
||||
# include <boost/python/make_constructor.hpp>
|
||||
# include <boost/python/init.hpp>
|
||||
# include <boost/python/to_python_converter.hpp>
|
||||
# include <boost/parameter/aux_/maybe.hpp>
|
||||
# include <boost/parameter/aux_/python/invoker.hpp>
|
||||
|
||||
namespace boost { namespace parameter { namespace python
|
||||
{
|
||||
namespace python_ = boost::python;
|
||||
}}}
|
||||
|
||||
namespace boost { namespace parameter { namespace python { namespace aux
|
||||
{
|
||||
|
||||
inline PyObject* unspecified_type()
|
||||
{
|
||||
static PyTypeObject unspecified = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Boost.Parameter.Unspecified", /* tp_name */
|
||||
PyType_Type.tp_basicsize, /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
0, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
};
|
||||
|
||||
if (unspecified.ob_type == 0)
|
||||
{
|
||||
unspecified.ob_type = &PyType_Type;
|
||||
PyType_Ready(&unspecified);
|
||||
}
|
||||
|
||||
return (PyObject*)&unspecified;
|
||||
}
|
||||
|
||||
struct empty_tag {};
|
||||
|
||||
struct empty_tag_to_python
|
||||
{
|
||||
static PyObject* convert(empty_tag)
|
||||
{
|
||||
return python_::xincref(unspecified_type());
|
||||
}
|
||||
};
|
||||
|
||||
}}}} // namespace boost::parameter::python::aux
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
|
||||
// Converts a Python value to a maybe<T>
|
||||
template <class T>
|
||||
struct arg_from_python<parameter::aux::maybe<T> >
|
||||
: arg_from_python<T>
|
||||
{
|
||||
arg_from_python(PyObject* p)
|
||||
: arg_from_python<T>(p)
|
||||
, empty(parameter::python::aux::unspecified_type() == p)
|
||||
{}
|
||||
|
||||
bool convertible() const
|
||||
{
|
||||
return empty || arg_from_python<T>::convertible();
|
||||
}
|
||||
|
||||
parameter::aux::maybe<T> operator()()
|
||||
{
|
||||
if (empty)
|
||||
{
|
||||
return parameter::aux::maybe<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return parameter::aux::maybe<T>(
|
||||
arg_from_python<T>::operator()()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool empty;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
namespace boost { namespace parameter { namespace python {
|
||||
|
||||
namespace aux
|
||||
{
|
||||
|
||||
template <class K>
|
||||
struct is_optional
|
||||
: mpl::not_<
|
||||
mpl::or_<typename K::required, typename K::optimized_default>
|
||||
>
|
||||
{};
|
||||
|
||||
template <class K, class Required, class Optimized, class T>
|
||||
struct arg_spec
|
||||
{
|
||||
typedef K keyword;
|
||||
typedef Required required;
|
||||
typedef T type;
|
||||
typedef Optimized optimized_default;
|
||||
};
|
||||
|
||||
template <class K, class T, class Optimized = mpl::false_>
|
||||
struct make_arg_spec_impl
|
||||
{
|
||||
typedef arg_spec<
|
||||
typename K::first, typename K::second, Optimized, T
|
||||
> type;
|
||||
};
|
||||
|
||||
template <class K, class T>
|
||||
struct make_arg_spec_impl<K, T, typename K::third>
|
||||
{
|
||||
typedef arg_spec<
|
||||
typename K::first, typename K::second, typename K::third, T
|
||||
> type;
|
||||
};
|
||||
|
||||
template <class K, class T>
|
||||
struct make_arg_spec
|
||||
: make_arg_spec_impl<K, T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class Spec, class State>
|
||||
struct combinations_op
|
||||
{
|
||||
typedef typename State::second bits;
|
||||
typedef typename State::first result0;
|
||||
|
||||
typedef typename mpl::if_<
|
||||
mpl::or_<
|
||||
typename Spec::required
|
||||
, typename Spec::optimized_default
|
||||
, mpl::bitand_<bits, mpl::long_<1> >
|
||||
>
|
||||
, typename mpl::push_back<result0, Spec>::type
|
||||
, result0
|
||||
>::type result;
|
||||
|
||||
typedef typename mpl::if_<
|
||||
mpl::or_<
|
||||
typename Spec::required
|
||||
, typename Spec::optimized_default
|
||||
>
|
||||
, bits
|
||||
, typename mpl::shift_right<bits, mpl::long_<1> >::type
|
||||
>::type next_bits;
|
||||
|
||||
typedef mpl::pair<
|
||||
result
|
||||
, next_bits
|
||||
> type;
|
||||
};
|
||||
|
||||
// Used as start value in the recursive arg() composition below.
|
||||
struct no_keywords
|
||||
{
|
||||
template <class T>
|
||||
T const& operator,(T const& x) const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Def, class F, class Iter, class End, class Keywords>
|
||||
void def_combination_aux0(
|
||||
Def def, F f, Iter, End, Keywords const& keywords, mpl::false_)
|
||||
{
|
||||
typedef typename mpl::deref<Iter>::type spec;
|
||||
typedef typename spec::keyword kw;
|
||||
|
||||
def_combination_aux(
|
||||
def, f, typename mpl::next<Iter>::type(), End()
|
||||
, (
|
||||
keywords, boost::python::arg(kw::keyword_name())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template <class Def, class F, class Iter, class End, class Keywords>
|
||||
void def_combination_aux0(
|
||||
Def def, F f, Iter, End, Keywords const& keywords, mpl::true_)
|
||||
{
|
||||
typedef typename mpl::deref<Iter>::type spec;
|
||||
typedef typename spec::keyword kw;
|
||||
|
||||
def_combination_aux(
|
||||
def, f, typename mpl::next<Iter>::type(), End()
|
||||
, (
|
||||
keywords, boost::python::arg(kw::keyword_name()) = empty_tag()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline void initialize_converter()
|
||||
{
|
||||
static python_::to_python_converter<empty_tag, empty_tag_to_python> x;
|
||||
}
|
||||
|
||||
template <class Def, class F, class Iter, class End, class Keywords>
|
||||
void def_combination_aux(
|
||||
Def def, F f, Iter, End, Keywords const& keywords)
|
||||
{
|
||||
typedef typename mpl::deref<Iter>::type spec;
|
||||
|
||||
typedef typename mpl::and_<
|
||||
typename spec::optimized_default
|
||||
, mpl::not_<typename spec::required>
|
||||
>::type optimized_default;
|
||||
|
||||
def_combination_aux0(
|
||||
def, f, Iter(), End(), keywords, optimized_default()
|
||||
);
|
||||
}
|
||||
|
||||
template <class Def, class F, class End, class Keywords>
|
||||
void def_combination_aux(
|
||||
Def def, F f, End, End, Keywords const& keywords)
|
||||
{
|
||||
def(f, keywords);
|
||||
}
|
||||
|
||||
template <class Def, class F, class End>
|
||||
void def_combination_aux(
|
||||
Def def, F f, End, End, no_keywords const&)
|
||||
{
|
||||
def(f);
|
||||
}
|
||||
|
||||
template <
|
||||
class Def, class Specs, class Bits, class Invoker
|
||||
>
|
||||
void def_combination(
|
||||
Def def, Specs*, Bits, Invoker*)
|
||||
{
|
||||
typedef typename mpl::fold<
|
||||
Specs
|
||||
, mpl::pair<mpl::vector0<>, Bits>
|
||||
, combinations_op<mpl::_2, mpl::_1>
|
||||
>::type combination0;
|
||||
|
||||
typedef typename combination0::first combination;
|
||||
|
||||
typedef typename mpl::apply_wrap1<
|
||||
Invoker, combination
|
||||
>::type invoker;
|
||||
|
||||
def_combination_aux(
|
||||
def
|
||||
, &invoker::execute
|
||||
, typename mpl::begin<combination>::type()
|
||||
, typename mpl::end<combination>::type()
|
||||
, no_keywords()
|
||||
);
|
||||
}
|
||||
|
||||
template <
|
||||
class Def, class Specs, class Bits, class End, class Invoker
|
||||
>
|
||||
void def_combinations(
|
||||
Def def, Specs*, Bits, End, Invoker*)
|
||||
{
|
||||
initialize_converter();
|
||||
|
||||
def_combination(def, (Specs*)0, Bits(), (Invoker*)0);
|
||||
|
||||
def_combinations(
|
||||
def
|
||||
, (Specs*)0
|
||||
, mpl::long_<Bits::value + 1>()
|
||||
, End()
|
||||
, (Invoker*)0
|
||||
);
|
||||
}
|
||||
|
||||
template <
|
||||
class Def, class Specs, class End, class Invoker
|
||||
>
|
||||
void def_combinations(
|
||||
Def, Specs*, End, End, Invoker*)
|
||||
{}
|
||||
|
||||
struct not_specified {};
|
||||
|
||||
template <class CallPolicies>
|
||||
struct call_policies_as_options
|
||||
{
|
||||
call_policies_as_options(CallPolicies const& call_policies)
|
||||
: call_policies(call_policies)
|
||||
{}
|
||||
|
||||
CallPolicies const& policies() const
|
||||
{
|
||||
return call_policies;
|
||||
}
|
||||
|
||||
char const* doc() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CallPolicies call_policies;
|
||||
};
|
||||
|
||||
template <class Class, class Options = not_specified>
|
||||
struct def_class
|
||||
{
|
||||
def_class(Class& cl, char const* name, Options options = Options())
|
||||
: cl(cl)
|
||||
, name(name)
|
||||
, options(options)
|
||||
{}
|
||||
|
||||
template <class F>
|
||||
void def(F f, not_specified const*) const
|
||||
{
|
||||
cl.def(name, f);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void def(F f, void const*) const
|
||||
{
|
||||
cl.def(name, f, options.doc(), options.policies());
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void operator()(F f) const
|
||||
{
|
||||
this->def(f, &options);
|
||||
}
|
||||
|
||||
template <class F, class Keywords>
|
||||
void def(F f, Keywords const& keywords, not_specified const*) const
|
||||
{
|
||||
cl.def(name, f, keywords);
|
||||
}
|
||||
|
||||
template <class F, class Keywords>
|
||||
void def(F f, Keywords const& keywords, void const*) const
|
||||
{
|
||||
cl.def(name, f, keywords, options.doc(), options.policies());
|
||||
}
|
||||
|
||||
template <class F, class Keywords>
|
||||
void operator()(F f, Keywords const& keywords) const
|
||||
{
|
||||
this->def(f, keywords, &options);
|
||||
}
|
||||
|
||||
Class& cl;
|
||||
char const* name;
|
||||
Options options;
|
||||
};
|
||||
|
||||
template <class Class, class CallPolicies = boost::python::default_call_policies>
|
||||
struct def_init
|
||||
{
|
||||
def_init(Class& cl, CallPolicies call_policies = CallPolicies())
|
||||
: cl(cl)
|
||||
, call_policies(call_policies)
|
||||
{}
|
||||
|
||||
template <class F>
|
||||
void operator()(F f) const
|
||||
{
|
||||
cl.def(
|
||||
"__init__"
|
||||
, boost::python::make_constructor(f, call_policies)
|
||||
);
|
||||
}
|
||||
|
||||
template <class F, class Keywords>
|
||||
void operator()(F f, Keywords const& keywords) const
|
||||
{
|
||||
cl.def(
|
||||
"__init__"
|
||||
, boost::python::make_constructor(f, call_policies, keywords)
|
||||
);
|
||||
}
|
||||
|
||||
Class& cl;
|
||||
CallPolicies call_policies;
|
||||
};
|
||||
|
||||
struct def_function
|
||||
{
|
||||
def_function(char const* name)
|
||||
: name(name)
|
||||
{}
|
||||
|
||||
template <class F>
|
||||
void operator()(F f) const
|
||||
{
|
||||
boost::python::def(name, f);
|
||||
}
|
||||
|
||||
template <class F, class Keywords>
|
||||
void operator()(F f, Keywords const& keywords) const
|
||||
{
|
||||
boost::python::def(name, f, keywords);
|
||||
}
|
||||
|
||||
char const* name;
|
||||
};
|
||||
|
||||
} // namespace aux
|
||||
|
||||
template <class M, class Signature>
|
||||
void def(char const* name, Signature)
|
||||
{
|
||||
typedef mpl::iterator_range<
|
||||
typename mpl::next<
|
||||
typename mpl::begin<Signature>::type
|
||||
>::type
|
||||
, typename mpl::end<Signature>::type
|
||||
> arg_types;
|
||||
|
||||
typedef typename mpl::transform<
|
||||
typename M::keywords
|
||||
, arg_types
|
||||
, aux::make_arg_spec<mpl::_1, mpl::_2>
|
||||
, mpl::back_inserter<mpl::vector0<> >
|
||||
>::type arg_specs;
|
||||
|
||||
typedef typename mpl::count_if<
|
||||
arg_specs
|
||||
, aux::is_optional<mpl::_1>
|
||||
>::type optional_arity;
|
||||
|
||||
typedef typename mpl::front<Signature>::type result_type;
|
||||
typedef typename mpl::shift_left<mpl::long_<1>, optional_arity>::type upper;
|
||||
|
||||
aux::def_combinations(
|
||||
aux::def_function(name)
|
||||
, (arg_specs*)0
|
||||
, mpl::long_<0>()
|
||||
, mpl::long_<upper::value>()
|
||||
, (aux::make_invoker<M, result_type>*)0
|
||||
);
|
||||
}
|
||||
|
||||
template <class M, class Class, class Signature>
|
||||
void def(Class& cl, char const* name, Signature)
|
||||
{
|
||||
typedef mpl::iterator_range<
|
||||
typename mpl::next<
|
||||
typename mpl::begin<Signature>::type
|
||||
>::type
|
||||
, typename mpl::end<Signature>::type
|
||||
> arg_types;
|
||||
|
||||
typedef typename mpl::transform<
|
||||
typename M::keywords
|
||||
, arg_types
|
||||
, aux::make_arg_spec<mpl::_1, mpl::_2>
|
||||
, mpl::back_inserter<mpl::vector0<> >
|
||||
>::type arg_specs;
|
||||
|
||||
typedef typename mpl::count_if<
|
||||
arg_specs
|
||||
, aux::is_optional<mpl::_1>
|
||||
>::type optional_arity;
|
||||
|
||||
typedef typename mpl::front<Signature>::type result_type;
|
||||
typedef typename mpl::shift_left<mpl::long_<1>, optional_arity>::type upper;
|
||||
|
||||
aux::def_combinations(
|
||||
aux::def_class<Class>(cl, name)
|
||||
, (arg_specs*)0
|
||||
, mpl::long_<0>()
|
||||
, mpl::long_<upper::value>()
|
||||
, (aux::make_invoker<M, result_type>*)0
|
||||
);
|
||||
}
|
||||
|
||||
namespace aux
|
||||
{
|
||||
|
||||
template <class K>
|
||||
struct keyword
|
||||
{
|
||||
typedef K type;
|
||||
};
|
||||
|
||||
template <class K>
|
||||
struct keyword<K*>
|
||||
{
|
||||
typedef K type;
|
||||
};
|
||||
|
||||
template <class K>
|
||||
struct keyword<K**>
|
||||
{
|
||||
typedef K type;
|
||||
};
|
||||
|
||||
template <class K>
|
||||
struct required
|
||||
{
|
||||
typedef mpl::true_ type;
|
||||
};
|
||||
|
||||
template <class K>
|
||||
struct required<K*>
|
||||
{
|
||||
typedef mpl::false_ type;
|
||||
};
|
||||
|
||||
template <class K>
|
||||
struct optimized
|
||||
{
|
||||
typedef mpl::true_ type;
|
||||
};
|
||||
|
||||
template <class K>
|
||||
struct optimized<K**>
|
||||
{
|
||||
typedef mpl::false_ type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct make_kw_spec;
|
||||
|
||||
template <class K, class T>
|
||||
struct make_kw_spec<K(T)>
|
||||
{
|
||||
typedef arg_spec<
|
||||
typename keyword<K>::type
|
||||
, typename required<K>::type
|
||||
, typename optimized<K>::type
|
||||
, T
|
||||
> type;
|
||||
};
|
||||
|
||||
} // namespace aux
|
||||
|
||||
template <class ParameterSpecs, class CallPolicies = boost::python::default_call_policies>
|
||||
struct init
|
||||
: boost::python::def_visitor<init<ParameterSpecs, CallPolicies> >
|
||||
{
|
||||
init(CallPolicies call_policies = CallPolicies())
|
||||
: call_policies(call_policies)
|
||||
{}
|
||||
|
||||
template <class CallPolicies1>
|
||||
init<ParameterSpecs, CallPolicies1>
|
||||
operator[](CallPolicies1 const& call_policies) const
|
||||
{
|
||||
return init<ParameterSpecs, CallPolicies1>(call_policies);
|
||||
}
|
||||
|
||||
template <class Class>
|
||||
void visit_aux(Class& cl, mpl::true_) const
|
||||
{
|
||||
cl.def(boost::python::init<>()[call_policies]);
|
||||
}
|
||||
|
||||
template <class Class>
|
||||
void visit_aux(Class& cl, mpl::false_) const
|
||||
{
|
||||
typedef typename mpl::transform<
|
||||
ParameterSpecs
|
||||
, aux::make_kw_spec<mpl::_>
|
||||
, mpl::back_inserter<mpl::vector0<> >
|
||||
>::type arg_specs;
|
||||
|
||||
typedef typename mpl::count_if<
|
||||
arg_specs
|
||||
, aux::is_optional<mpl::_>
|
||||
>::type optional_arity;
|
||||
|
||||
typedef typename mpl::shift_left<mpl::long_<1>, optional_arity>::type upper;
|
||||
|
||||
aux::def_combinations(
|
||||
aux::def_init<Class, CallPolicies>(cl, call_policies)
|
||||
, (arg_specs*)0
|
||||
, mpl::long_<0>()
|
||||
, mpl::long_<upper::value>()
|
||||
, (aux::make_init_invoker<typename Class::wrapped_type>*)0
|
||||
);
|
||||
}
|
||||
|
||||
template <class Class>
|
||||
void visit(Class& cl) const
|
||||
{
|
||||
visit_aux(cl, mpl::empty<ParameterSpecs>());
|
||||
}
|
||||
|
||||
CallPolicies call_policies;
|
||||
};
|
||||
|
||||
template <class ParameterSpecs, class CallPolicies = boost::python::default_call_policies>
|
||||
struct call
|
||||
: boost::python::def_visitor<call<ParameterSpecs, CallPolicies> >
|
||||
{
|
||||
call(CallPolicies const& call_policies = CallPolicies())
|
||||
: call_policies(call_policies)
|
||||
{}
|
||||
|
||||
template <class CallPolicies1>
|
||||
call<ParameterSpecs, CallPolicies1>
|
||||
operator[](CallPolicies1 const& call_policies) const
|
||||
{
|
||||
return call<ParameterSpecs, CallPolicies1>(call_policies);
|
||||
}
|
||||
|
||||
template <class Class>
|
||||
void visit(Class& cl) const
|
||||
{
|
||||
typedef mpl::iterator_range<
|
||||
typename mpl::next<
|
||||
typename mpl::begin<ParameterSpecs>::type
|
||||
>::type
|
||||
, typename mpl::end<ParameterSpecs>::type
|
||||
> arg_types;
|
||||
|
||||
typedef typename mpl::front<ParameterSpecs>::type result_type;
|
||||
|
||||
typedef typename mpl::transform<
|
||||
arg_types
|
||||
, aux::make_kw_spec<mpl::_>
|
||||
, mpl::back_inserter<mpl::vector0<> >
|
||||
>::type arg_specs;
|
||||
|
||||
typedef typename mpl::count_if<
|
||||
arg_specs
|
||||
, aux::is_optional<mpl::_>
|
||||
>::type optional_arity;
|
||||
|
||||
typedef typename mpl::shift_left<mpl::long_<1>, optional_arity>::type upper;
|
||||
|
||||
typedef aux::call_policies_as_options<CallPolicies> options;
|
||||
|
||||
aux::def_combinations(
|
||||
aux::def_class<Class, options>(cl, "__call__", options(call_policies))
|
||||
, (arg_specs*)0
|
||||
, mpl::long_<0>()
|
||||
, mpl::long_<upper::value>()
|
||||
, (aux::make_call_invoker<typename Class::wrapped_type, result_type>*)0
|
||||
);
|
||||
}
|
||||
|
||||
CallPolicies call_policies;
|
||||
};
|
||||
|
||||
template <class Fwd, class ParameterSpecs>
|
||||
struct function
|
||||
: boost::python::def_visitor<function<Fwd, ParameterSpecs> >
|
||||
{
|
||||
template <class Class, class Options>
|
||||
void visit(Class& cl, char const* name, Options const& options) const
|
||||
{
|
||||
typedef mpl::iterator_range<
|
||||
typename mpl::next<
|
||||
typename mpl::begin<ParameterSpecs>::type
|
||||
>::type
|
||||
, typename mpl::end<ParameterSpecs>::type
|
||||
> arg_types;
|
||||
|
||||
typedef typename mpl::front<ParameterSpecs>::type result_type;
|
||||
|
||||
typedef typename mpl::transform<
|
||||
arg_types
|
||||
, aux::make_kw_spec<mpl::_>
|
||||
, mpl::back_inserter<mpl::vector0<> >
|
||||
>::type arg_specs;
|
||||
|
||||
typedef typename mpl::count_if<
|
||||
arg_specs
|
||||
, aux::is_optional<mpl::_>
|
||||
>::type optional_arity;
|
||||
|
||||
typedef typename mpl::shift_left<mpl::long_<1>, optional_arity>::type upper;
|
||||
|
||||
aux::def_combinations(
|
||||
aux::def_class<Class, Options>(cl, name, options)
|
||||
, (arg_specs*)0
|
||||
, mpl::long_<0>()
|
||||
, mpl::long_<upper::value>()
|
||||
, (aux::make_member_invoker<
|
||||
Fwd, result_type, typename Class::wrapped_type
|
||||
>*)0
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::parameter::python
|
||||
|
||||
#endif // BOOST_PARAMETER_PYTHON_060209_HPP
|
||||
|
||||
30
include/boost/parameter/value_type.hpp
Executable file → Normal file
30
include/boost/parameter/value_type.hpp
Executable file → Normal file
@@ -12,18 +12,13 @@
|
||||
# include <boost/parameter/aux_/void.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
# include <boost/mpl/eval_if.hpp>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace parameter {
|
||||
|
||||
// A metafunction that, given an argument pack, returns the type of
|
||||
// the parameter identified by the given keyword. If no such
|
||||
// parameter has been specified, returns Default
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
template <class Parameters, class Keyword, class Default>
|
||||
struct value_type0
|
||||
{
|
||||
@@ -41,14 +36,9 @@ struct value_type0
|
||||
# endif
|
||||
|
||||
template <class Parameters, class Keyword, class Default = void_>
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
struct value_type
|
||||
# else
|
||||
struct value_type_eti
|
||||
# endif
|
||||
{
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
typedef typename mpl::eval_if<
|
||||
mpl::is_placeholder<Parameters>
|
||||
, mpl::identity<int>
|
||||
@@ -67,24 +57,8 @@ struct value_type_eti
|
||||
));
|
||||
# endif
|
||||
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,value_type,(Parameters,Keyword,Default))
|
||||
# endif
|
||||
};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
template <class Parameters, class Keyword, class Default = void_>
|
||||
struct value_type
|
||||
{
|
||||
typedef typename mpl::eval_if<
|
||||
is_same<Parameters, int>
|
||||
, mpl::identity<int>
|
||||
, value_type_eti<Parameters, Keyword, Default>
|
||||
>::type type;
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,value_type,(Parameters,Keyword,Default))
|
||||
};
|
||||
# endif
|
||||
|
||||
// A metafunction that, given an argument pack, returns the type of
|
||||
// the parameter identified by the given keyword. If no such
|
||||
|
||||
0
index.html
Executable file → Normal file
0
index.html
Executable file → Normal file
17
meta/libraries.json
Normal file
17
meta/libraries.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"key": "parameter",
|
||||
"name": "Parameter",
|
||||
"authors": [
|
||||
"David Abrahams",
|
||||
"Daniel Wallin"
|
||||
],
|
||||
"description": "Boost.Parameter Library - Write functions that accept arguments by name.",
|
||||
"category": [
|
||||
"Emulation",
|
||||
"Programming"
|
||||
],
|
||||
"maintainers": [
|
||||
"David Abrahams <dave -at- boost-consulting.com>",
|
||||
"Daniel Wallin <daniel -at- boostpro.com>"
|
||||
]
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import python ;
|
||||
project boost/parameter
|
||||
: default-build <warnings>off
|
||||
;
|
||||
|
||||
build-project literate ;
|
||||
|
||||
test-suite "parameter"
|
||||
: [ run basics.cpp ]
|
||||
|
||||
0
test/basics.cpp
Executable file → Normal file
0
test/basics.cpp
Executable file → Normal file
0
test/basics.hpp
Executable file → Normal file
0
test/basics.hpp
Executable file → Normal file
0
test/deduced.cpp
Executable file → Normal file
0
test/deduced.cpp
Executable file → Normal file
0
test/deduced.hpp
Executable file → Normal file
0
test/deduced.hpp
Executable file → Normal file
0
test/deduced_dependent_predicate.cpp
Executable file → Normal file
0
test/deduced_dependent_predicate.cpp
Executable file → Normal file
0
test/deduced_unmatched_arg.cpp
Executable file → Normal file
0
test/deduced_unmatched_arg.cpp
Executable file → Normal file
0
test/duplicates.cpp
Executable file → Normal file
0
test/duplicates.cpp
Executable file → Normal file
0
test/earwicker.cpp
Executable file → Normal file
0
test/earwicker.cpp
Executable file → Normal file
0
test/efficiency.cpp
Executable file → Normal file
0
test/efficiency.cpp
Executable file → Normal file
33
test/literate/Jamfile.v2
Normal file
33
test/literate/Jamfile.v2
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
import testing ;
|
||||
|
||||
run extracting-parameter-types0.cpp ;
|
||||
run extracting-parameter-types1.cpp ;
|
||||
compile template-keywords0.cpp ;
|
||||
compile template-keywords1.cpp ;
|
||||
compile top-level0.cpp ;
|
||||
compile headers-and-namespaces0.cpp ;
|
||||
compile predicate-requirements0.cpp ;
|
||||
compile handling-out-parameters0.cpp ;
|
||||
compile writing-the-function0.cpp ;
|
||||
run building-argumentpacks0.cpp ;
|
||||
compile defining-the-keywords0.cpp ;
|
||||
compile defining-the-keywords1.cpp ;
|
||||
compile exercising-the-code-so-far0.cpp ;
|
||||
run lazy-default-computation0.cpp ;
|
||||
run lazy-default-computation1.cpp ;
|
||||
run namespaces0.cpp ;
|
||||
run namespaces1.cpp ;
|
||||
run namespaces2.cpp ;
|
||||
run namespaces3.cpp ;
|
||||
compile optional-parameters0.cpp ;
|
||||
compile static-member-functions0.cpp ;
|
||||
run parameter-enabled-constructors0.cpp ;
|
||||
compile required-parameters0.cpp ;
|
||||
compile class-template-skeleton0.cpp ;
|
||||
compile deduced-template-parameters0.cpp ;
|
||||
compile deduced-parameters0.cpp ;
|
||||
compile default-expression-evaluation0.cpp ;
|
||||
compile parameter-enabled-member-functions0.cpp ;
|
||||
compile parameter-enabled-member-functions1.cpp ;
|
||||
run fine-grained-name-control0.cpp ;
|
||||
6
test/literate/README
Normal file
6
test/literate/README
Normal file
@@ -0,0 +1,6 @@
|
||||
These tests were extracted from the Boost.Parameter documentation
|
||||
with:
|
||||
|
||||
python ../../../../tools/litre/tool.py \
|
||||
../../../../libs/parameter/doc/index.rst \
|
||||
--dump_dir=.
|
||||
47
test/literate/building-argumentpacks0.cpp
Normal file
47
test/literate/building-argumentpacks0.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
template <class ArgumentPack>
|
||||
int print_index(ArgumentPack const& args)
|
||||
{
|
||||
std::cout << "index = " << args[_index] << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int x = print_index(_index = 3); // prints "index = 3"
|
||||
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
|
||||
template <class ArgumentPack>
|
||||
int print_name_and_index(ArgumentPack const& args)
|
||||
{
|
||||
std::cout << "name = " << args[_name] << "; ";
|
||||
return print_index(args);
|
||||
}
|
||||
|
||||
int y = print_name_and_index((_index = 3, _name = "jones"));
|
||||
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
using parameter::required;
|
||||
using parameter::optional;
|
||||
using boost::is_convertible;
|
||||
using boost::mpl::_;
|
||||
parameter::parameters<
|
||||
required<tag::name, is_convertible<_,char const*> >
|
||||
, optional<tag::index, is_convertible<_,int> >
|
||||
> spec;
|
||||
|
||||
char const sam[] = "sam";
|
||||
int twelve = 12;
|
||||
|
||||
int z0 = print_name_and_index( spec(sam, twelve) );
|
||||
|
||||
int z1 = print_name_and_index(
|
||||
spec(_index=12, _name="sam")
|
||||
);
|
||||
int main()
|
||||
{}
|
||||
|
||||
16
test/literate/class-template-skeleton0.cpp
Normal file
16
test/literate/class-template-skeleton0.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <
|
||||
class A0
|
||||
, class A1 = parameter::void_
|
||||
, class A2 = parameter::void_
|
||||
, class A3 = parameter::void_
|
||||
>
|
||||
struct class_
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
74
test/literate/deduced-parameters0.cpp
Normal file
74
test/literate/deduced-parameters0.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(func)
|
||||
BOOST_PARAMETER_NAME(docstring)
|
||||
BOOST_PARAMETER_NAME(keywords)
|
||||
BOOST_PARAMETER_NAME(policies)
|
||||
|
||||
struct default_call_policies
|
||||
{};
|
||||
|
||||
struct no_keywords
|
||||
{};
|
||||
|
||||
struct keywords
|
||||
{};
|
||||
|
||||
template <class T>
|
||||
struct is_keyword_expression
|
||||
: boost::mpl::false_
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct is_keyword_expression<keywords>
|
||||
: boost::mpl::true_
|
||||
{};
|
||||
|
||||
default_call_policies some_policies;
|
||||
|
||||
void f()
|
||||
{}
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(void), def, tag,
|
||||
|
||||
(required (name,(char const*)) (func,*) ) // nondeduced
|
||||
|
||||
(deduced
|
||||
(optional
|
||||
(docstring, (char const*), "")
|
||||
|
||||
(keywords
|
||||
, *(is_keyword_expression<mpl::_>) // see 5
|
||||
, no_keywords())
|
||||
|
||||
(policies
|
||||
, *(mpl::not_<
|
||||
mpl::or_<
|
||||
boost::is_convertible<mpl::_, char const*>
|
||||
, is_keyword_expression<mpl::_> // see 5
|
||||
>
|
||||
>)
|
||||
, default_call_policies()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
def("f", &f, some_policies, "Documentation for f");
|
||||
def("f", &f, "Documentation for f", some_policies);
|
||||
|
||||
def(
|
||||
"f", &f
|
||||
, _policies = some_policies, "Documentation for f");
|
||||
}
|
||||
|
||||
124
test/literate/deduced-template-parameters0.cpp
Normal file
124
test/literate/deduced-template-parameters0.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <memory>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
using namespace boost::parameter;
|
||||
using boost::mpl::_;
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable)
|
||||
|
||||
}}
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail { struct bases_base {}; }
|
||||
|
||||
template <class A0 = void, class A1 = void, class A2 = void >
|
||||
struct bases : detail::bases_base
|
||||
{};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
namespace boost { namespace python {
|
||||
typedef parameter::parameters<
|
||||
required<tag::class_type, is_class<_> >
|
||||
|
||||
, parameter::optional<
|
||||
deduced<tag::base_list>
|
||||
, is_base_and_derived<detail::bases_base,_>
|
||||
>
|
||||
|
||||
, parameter::optional<
|
||||
deduced<tag::held_type>
|
||||
, mpl::not_<
|
||||
mpl::or_<
|
||||
is_base_and_derived<detail::bases_base,_>
|
||||
, is_same<noncopyable,_>
|
||||
>
|
||||
>
|
||||
>
|
||||
|
||||
, parameter::optional<deduced<tag::copyable>, is_same<noncopyable,_> >
|
||||
|
||||
> class_signature;
|
||||
template <
|
||||
class A0
|
||||
, class A1 = parameter::void_
|
||||
, class A2 = parameter::void_
|
||||
, class A3 = parameter::void_
|
||||
>
|
||||
struct class_
|
||||
{
|
||||
// Create ArgumentPack
|
||||
typedef typename
|
||||
class_signature::bind<A0,A1,A2,A3>::type
|
||||
args;
|
||||
|
||||
// Extract first logical parameter.
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::class_type>::type class_type;
|
||||
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::base_list, bases<> >::type base_list;
|
||||
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::held_type, class_type>::type held_type;
|
||||
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::copyable, void>::type copyable;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
struct B {};
|
||||
struct D {};
|
||||
|
||||
using boost::python::bases;
|
||||
typedef boost::python::class_<B, boost::noncopyable> c1;
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
typedef boost::python::class_<D, std::auto_ptr<D>, bases<B> > c2;
|
||||
|
||||
#else
|
||||
|
||||
typedef boost::python::class_<D, std::unique_ptr<D>, bases<B> > c2;
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<c1::class_type, B>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<c1::base_list, bases<> >));
|
||||
BOOST_MPL_ASSERT((boost::is_same<c1::held_type, B>));
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same<c1::copyable, boost::noncopyable>
|
||||
));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<c2::class_type, D>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<c2::base_list, bases<B> >));
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same<c2::held_type, std::auto_ptr<D> >
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same<c2::held_type, std::unique_ptr<D> >
|
||||
));
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<c2::copyable, void>));
|
||||
39
test/literate/default-expression-evaluation0.cpp
Normal file
39
test/literate/default-expression-evaluation0.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
|
||||
BOOST_PARAMETER_NAME(graph)
|
||||
BOOST_PARAMETER_NAME(visitor)
|
||||
BOOST_PARAMETER_NAME(root_vertex)
|
||||
BOOST_PARAMETER_NAME(index_map)
|
||||
BOOST_PARAMETER_NAME(color_map)
|
||||
#include <boost/graph/depth_first_search.hpp> // for dfs_visitor
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(void), depth_first_search, tag
|
||||
|
||||
, (required
|
||||
(graph, *)
|
||||
(visitor, *)
|
||||
(root_vertex, *)
|
||||
(index_map, *)
|
||||
(color_map, *)
|
||||
)
|
||||
|
||||
)
|
||||
{
|
||||
std::cout << "graph=" << graph << std::endl;
|
||||
std::cout << "visitor=" << visitor << std::endl;
|
||||
std::cout << "root_vertex=" << root_vertex << std::endl;
|
||||
std::cout << "index_map=" << index_map << std::endl;
|
||||
std::cout << "color_map=" << color_map << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
depth_first_search(1, 2, 3, 4, 5);
|
||||
|
||||
depth_first_search(
|
||||
"1", '2', _color_map = '5',
|
||||
_index_map = "4", _root_vertex = "3");
|
||||
}
|
||||
10
test/literate/defining-the-keywords0.cpp
Normal file
10
test/literate/defining-the-keywords0.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <boost/parameter/name.hpp>
|
||||
|
||||
namespace graphs
|
||||
{
|
||||
BOOST_PARAMETER_NAME(graph) // Note: no semicolon
|
||||
BOOST_PARAMETER_NAME(visitor)
|
||||
BOOST_PARAMETER_NAME(root_vertex)
|
||||
BOOST_PARAMETER_NAME(index_map)
|
||||
BOOST_PARAMETER_NAME(color_map)
|
||||
}
|
||||
13
test/literate/defining-the-keywords1.cpp
Normal file
13
test/literate/defining-the-keywords1.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
namespace graphs
|
||||
{
|
||||
namespace tag { struct graph; } // keyword tag type
|
||||
|
||||
namespace // unnamed
|
||||
{
|
||||
// A reference to the keyword object
|
||||
boost::parameter::keyword<tag::graph>& _graph
|
||||
= boost::parameter::keyword<tag::graph>::get();
|
||||
}
|
||||
}
|
||||
118
test/literate/exercising-the-code-so-far0.cpp
Normal file
118
test/literate/exercising-the-code-so-far0.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <memory>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
using namespace boost::parameter;
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable)
|
||||
|
||||
template <class B = int>
|
||||
struct bases
|
||||
{};
|
||||
|
||||
}}
|
||||
namespace boost { namespace python {
|
||||
|
||||
using boost::mpl::_;
|
||||
|
||||
typedef parameter::parameters<
|
||||
required<tag::class_type, boost::is_class<_> >
|
||||
, parameter::optional<tag::base_list, mpl::is_sequence<_> >
|
||||
, parameter::optional<tag::held_type>
|
||||
, parameter::optional<tag::copyable>
|
||||
> class_signature;
|
||||
|
||||
}}
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <
|
||||
class A0
|
||||
, class A1 = parameter::void_
|
||||
, class A2 = parameter::void_
|
||||
, class A3 = parameter::void_
|
||||
>
|
||||
struct class_
|
||||
{
|
||||
// Create ArgumentPack
|
||||
typedef typename
|
||||
class_signature::bind<A0,A1,A2,A3>::type
|
||||
args;
|
||||
|
||||
// Extract first logical parameter.
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::class_type>::type class_type;
|
||||
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::base_list, bases<> >::type base_list;
|
||||
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::held_type, class_type>::type held_type;
|
||||
|
||||
typedef typename parameter::value_type<
|
||||
args, tag::copyable, void>::type copyable;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
using boost::python::class_type;
|
||||
using boost::python::copyable;
|
||||
using boost::python::held_type;
|
||||
using boost::python::base_list;
|
||||
using boost::python::bases;
|
||||
|
||||
struct B {};
|
||||
struct D {};
|
||||
typedef boost::python::class_<
|
||||
class_type<B>, copyable<boost::noncopyable>
|
||||
> c1;
|
||||
|
||||
typedef boost::python::class_<
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
D, held_type<std::auto_ptr<D> >, base_list<bases<B> >
|
||||
|
||||
#else
|
||||
|
||||
D, held_type<std::unique_ptr<D> >, base_list<bases<B> >
|
||||
|
||||
#endif
|
||||
|
||||
> c2;
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<c1::class_type, B>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<c1::base_list, bases<> >));
|
||||
BOOST_MPL_ASSERT((boost::is_same<c1::held_type, B>));
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same<c1::copyable, boost::noncopyable>
|
||||
));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<c2::class_type, D>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<c2::base_list, bases<B> >));
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same<c2::held_type, std::auto_ptr<D> >
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_MPL_ASSERT((
|
||||
boost::is_same<c2::held_type, std::unique_ptr<D> >
|
||||
));
|
||||
|
||||
#endif
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<c2::copyable, void>));
|
||||
28
test/literate/extracting-parameter-types0.cpp
Normal file
28
test/literate/extracting-parameter-types0.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <cassert>
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
template <class Name, class Index>
|
||||
int deduce_arg_types_impl(Name& name, Index& index)
|
||||
{
|
||||
Name& n2 = name; // we know the types
|
||||
Index& i2 = index;
|
||||
return index;
|
||||
}
|
||||
|
||||
template <class ArgumentPack>
|
||||
int deduce_arg_types(ArgumentPack const& args)
|
||||
{
|
||||
return deduce_arg_types_impl(args[_name], args[_index|42]);
|
||||
}
|
||||
int a1 = deduce_arg_types((_name = "foo"));
|
||||
int a2 = deduce_arg_types((_name = "foo", _index = 3));
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(a1 == 42);
|
||||
assert(a2 == 3);
|
||||
}
|
||||
|
||||
21
test/literate/extracting-parameter-types1.cpp
Normal file
21
test/literate/extracting-parameter-types1.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
template <class ArgumentPack>
|
||||
typename parameter::value_type<ArgumentPack, tag::index, int>::type
|
||||
twice_index(ArgumentPack const& args)
|
||||
{
|
||||
return 2 * args[_index|42];
|
||||
}
|
||||
|
||||
int six = twice_index(_index = 3);
|
||||
int main()
|
||||
{
|
||||
assert(six == 6);
|
||||
}
|
||||
|
||||
15
test/literate/fine-grained-name-control0.cpp
Normal file
15
test/literate/fine-grained-name-control0.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
BOOST_PARAMETER_NAME((pass_foo, keywords) foo)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(int), f,
|
||||
keywords, (required (foo, *)))
|
||||
{
|
||||
return foo + 1;
|
||||
}
|
||||
|
||||
int x = f(pass_foo = 41);
|
||||
int main()
|
||||
{}
|
||||
|
||||
30
test/literate/handling-out-parameters0.cpp
Normal file
30
test/literate/handling-out-parameters0.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
int vertex_index = 0;
|
||||
|
||||
template <class T = int>
|
||||
struct dfs_visitor
|
||||
{};
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_NAME(graph)
|
||||
|
||||
BOOST_PARAMETER_NAME(visitor)
|
||||
BOOST_PARAMETER_NAME(root_vertex)
|
||||
BOOST_PARAMETER_NAME(index_map)
|
||||
BOOST_PARAMETER_NAME(color_map)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION((void), f, tag,
|
||||
(required (graph, *))
|
||||
(optional
|
||||
(visitor, *, boost::dfs_visitor<>())
|
||||
(root_vertex, *, *vertices(graph).first)
|
||||
(index_map, *, get(boost::vertex_index,graph))
|
||||
(in_out(color_map), *,
|
||||
default_color_map(num_vertices(graph), index_map) )
|
||||
)
|
||||
) {}
|
||||
|
||||
3
test/literate/headers-and-namespaces0.cpp
Normal file
3
test/literate/headers-and-namespaces0.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
using boost::parameter::keyword;
|
||||
|
||||
24
test/literate/lazy-default-computation0.cpp
Normal file
24
test/literate/lazy-default-computation0.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
BOOST_PARAMETER_NAME(s1)
|
||||
BOOST_PARAMETER_NAME(s2)
|
||||
BOOST_PARAMETER_NAME(s3)
|
||||
|
||||
template <class ArgumentPack>
|
||||
std::string f(ArgumentPack const& args)
|
||||
{
|
||||
std::string const& s1 = args[_s1];
|
||||
std::string const& s2 = args[_s2];
|
||||
typename parameter::binding<
|
||||
ArgumentPack,tag::s3,std::string
|
||||
>::type s3 = args[_s3|(s1+s2)]; // always constructs s1+s2
|
||||
return s3;
|
||||
}
|
||||
|
||||
std::string x = f((_s1="hello,", _s2=" world", _s3="hi world"));
|
||||
int main()
|
||||
{}
|
||||
|
||||
30
test/literate/lazy-default-computation1.cpp
Normal file
30
test/literate/lazy-default-computation1.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/parameter.hpp>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
|
||||
BOOST_PARAMETER_NAME(s1)
|
||||
BOOST_PARAMETER_NAME(s2)
|
||||
BOOST_PARAMETER_NAME(s3)
|
||||
|
||||
template <class ArgumentPack>
|
||||
std::string f(ArgumentPack const& args)
|
||||
{
|
||||
std::string const& s1 = args[_s1];
|
||||
std::string const& s2 = args[_s2];
|
||||
typename parameter::binding<
|
||||
ArgumentPack, tag::s3, std::string
|
||||
>::type s3 = args[_s3
|
||||
|| boost::bind(std::plus<std::string>(), boost::ref(s1), boost::ref(s2)) ];
|
||||
return s3;
|
||||
}
|
||||
|
||||
std::string x = f((_s1="hello,", _s2=" world", _s3="hi world"));
|
||||
|
||||
int main()
|
||||
{}
|
||||
|
||||
20
test/literate/namespaces0.cpp
Normal file
20
test/literate/namespaces0.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
namespace lib
|
||||
{
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(int), f, tag,
|
||||
(optional (name,*,"bob")(index,(int),1))
|
||||
)
|
||||
{
|
||||
std::cout << name << ":" << index << std::endl;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
int x = lib::f(lib::_name = "jill", lib::_index = 1);
|
||||
int main() {}
|
||||
|
||||
23
test/literate/namespaces1.cpp
Normal file
23
test/literate/namespaces1.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
namespace lib
|
||||
{
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(int), f, tag,
|
||||
(optional (name,*,"bob")(index,(int),1))
|
||||
)
|
||||
{
|
||||
std::cout << name << ":" << index << std::endl;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
using lib::_name;
|
||||
using lib::_index;
|
||||
|
||||
int x = lib::f(_name = "jill", _index = 1);
|
||||
int main() {}
|
||||
|
||||
21
test/literate/namespaces2.cpp
Normal file
21
test/literate/namespaces2.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
namespace lib
|
||||
{
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(int), f, tag,
|
||||
(optional (name,*,"bob")(index,(int),1))
|
||||
)
|
||||
{
|
||||
std::cout << name << ":" << index << std::endl;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
using namespace lib;
|
||||
int x = f(_name = "jill", _index = 3);
|
||||
int main() {}
|
||||
|
||||
25
test/literate/namespaces3.cpp
Normal file
25
test/literate/namespaces3.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
namespace lib
|
||||
{
|
||||
namespace keywords
|
||||
{
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(int), f, keywords::tag,
|
||||
(optional (name,*,"bob")(index,(int),1))
|
||||
)
|
||||
{
|
||||
std::cout << name << ":" << index << std::endl;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
using namespace lib::keywords;
|
||||
int y = lib::f(_name = "bob", _index = 2);
|
||||
int main() {}
|
||||
|
||||
28
test/literate/optional-parameters0.cpp
Normal file
28
test/literate/optional-parameters0.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
int vertex_index = 0;
|
||||
|
||||
template <class T = int>
|
||||
struct dfs_visitor
|
||||
{};
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_NAME(graph)
|
||||
BOOST_PARAMETER_NAME(visitor)
|
||||
BOOST_PARAMETER_NAME(root_vertex)
|
||||
BOOST_PARAMETER_NAME(index_map)
|
||||
BOOST_PARAMETER_NAME(color_map)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION((void), f, tag,
|
||||
(required (graph, *))
|
||||
(optional (visitor, *, boost::dfs_visitor<>())
|
||||
(root_vertex, *, *vertices(graph).first)
|
||||
(index_map, *, get(boost::vertex_index,graph))
|
||||
(in_out(color_map), *,
|
||||
default_color_map(num_vertices(graph), index_map) )
|
||||
)
|
||||
) {}
|
||||
|
||||
31
test/literate/parameter-enabled-constructors0.cpp
Normal file
31
test/literate/parameter-enabled-constructors0.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
BOOST_PARAMETER_NAME(name)
|
||||
BOOST_PARAMETER_NAME(index)
|
||||
|
||||
struct myclass_impl
|
||||
{
|
||||
template <class ArgumentPack>
|
||||
myclass_impl(ArgumentPack const& args)
|
||||
{
|
||||
std::cout << "name = " << args[_name]
|
||||
<< "; index = " << args[_index | 42]
|
||||
<< std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct myclass : myclass_impl
|
||||
{
|
||||
BOOST_PARAMETER_CONSTRUCTOR(
|
||||
myclass, (myclass_impl), tag
|
||||
, (required (name,*)) (optional (index,*))) // no semicolon
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
myclass x("bob", 3); // positional
|
||||
myclass y(_index = 12, _name = "sally"); // named
|
||||
myclass z("june"); // positional/defaulted
|
||||
}
|
||||
|
||||
15
test/literate/parameter-enabled-member-functions0.cpp
Normal file
15
test/literate/parameter-enabled-member-functions0.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
using namespace boost::parameter;
|
||||
BOOST_PARAMETER_NAME(arg1)
|
||||
BOOST_PARAMETER_NAME(arg2)
|
||||
|
||||
struct callable2
|
||||
{
|
||||
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
|
||||
(void), call, tag, (required (arg1,(int))(arg2,(int))))
|
||||
{
|
||||
std::cout << arg1 << ", " << arg2 << std::endl;
|
||||
}
|
||||
};
|
||||
16
test/literate/parameter-enabled-member-functions1.cpp
Normal file
16
test/literate/parameter-enabled-member-functions1.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME(arg1)
|
||||
BOOST_PARAMETER_NAME(arg2)
|
||||
using namespace boost::parameter;
|
||||
struct callable2
|
||||
{
|
||||
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
|
||||
(void), call, tag, (required (arg1,(int))(arg2,(int))))
|
||||
{
|
||||
call_impl(arg1,arg2);
|
||||
}
|
||||
private:
|
||||
void call_impl(int, int); // implemented elsewhere.
|
||||
};
|
||||
103
test/literate/predicate-requirements0.cpp
Normal file
103
test/literate/predicate-requirements0.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
#include <boost/graph/depth_first_search.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME((_graph, graphs) graph)
|
||||
BOOST_PARAMETER_NAME((_visitor, graphs) visitor)
|
||||
BOOST_PARAMETER_NAME((_root_vertex, graphs) root_vertex)
|
||||
BOOST_PARAMETER_NAME((_index_map, graphs) index_map)
|
||||
BOOST_PARAMETER_NAME((_color_map, graphs) color_map)
|
||||
|
||||
using boost::mpl::_;
|
||||
// We first need to define a few metafunction that we use in the
|
||||
// predicates below.
|
||||
|
||||
template <class G>
|
||||
struct traversal_category
|
||||
{
|
||||
typedef typename boost::graph_traits<G>::traversal_category type;
|
||||
};
|
||||
|
||||
template <class G>
|
||||
struct vertex_descriptor
|
||||
{
|
||||
typedef typename boost::graph_traits<G>::vertex_descriptor type;
|
||||
};
|
||||
|
||||
template <class G>
|
||||
struct value_type
|
||||
{
|
||||
typedef typename boost::property_traits<G>::value_type type;
|
||||
};
|
||||
|
||||
template <class G>
|
||||
struct key_type
|
||||
{
|
||||
typedef typename boost::property_traits<G>::key_type type;
|
||||
};
|
||||
|
||||
template<class Size, class IndexMap>
|
||||
boost::iterator_property_map<
|
||||
boost::default_color_type*, IndexMap
|
||||
, boost::default_color_type, boost::default_color_type&
|
||||
>
|
||||
default_color_map(Size num_vertices, IndexMap const& index_map)
|
||||
{
|
||||
std::vector<boost::default_color_type> colors(num_vertices);
|
||||
return &colors[0];
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(void), depth_first_search, graphs
|
||||
|
||||
, (required
|
||||
(graph
|
||||
, *(boost::mpl::and_<
|
||||
boost::is_convertible<
|
||||
traversal_category<_>, boost::incidence_graph_tag
|
||||
>
|
||||
, boost::is_convertible<
|
||||
traversal_category<_>, boost::vertex_list_graph_tag
|
||||
>
|
||||
>) ))
|
||||
|
||||
(optional
|
||||
(visitor, *, boost::dfs_visitor<>()) // not checkable
|
||||
|
||||
(root_vertex
|
||||
, (vertex_descriptor<graphs::graph::_>)
|
||||
, *vertices(graph).first)
|
||||
|
||||
(index_map
|
||||
, *(boost::mpl::and_<
|
||||
boost::is_integral<value_type<_> >
|
||||
, boost::is_same<
|
||||
vertex_descriptor<graphs::graph::_>, key_type<_>
|
||||
>
|
||||
>)
|
||||
, get(boost::vertex_index,graph))
|
||||
|
||||
(in_out(color_map)
|
||||
, *(boost::is_same<
|
||||
vertex_descriptor<graphs::graph::_>, key_type<_>
|
||||
>)
|
||||
, default_color_map(num_vertices(graph), index_map) )
|
||||
)
|
||||
)
|
||||
{}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> G;
|
||||
|
||||
enum {u, v, w, x, y, z, N};
|
||||
typedef std::pair<int, int> E;
|
||||
E edges[] = {E(u, v), E(u, x), E(x, v), E(y, x), E(v, y), E(w, y),
|
||||
E(w,z), E(z, z)};
|
||||
G g(edges, edges + sizeof(edges) / sizeof(E), N);
|
||||
|
||||
::depth_first_search(g);
|
||||
::depth_first_search(g, _root_vertex = (int)x);
|
||||
}
|
||||
|
||||
9
test/literate/required-parameters0.cpp
Normal file
9
test/literate/required-parameters0.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME(graph)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION((void), f, tag,
|
||||
(required (graph, *) )
|
||||
) {}
|
||||
|
||||
14
test/literate/static-member-functions0.cpp
Normal file
14
test/literate/static-member-functions0.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
#include <iostream>
|
||||
using namespace boost::parameter;
|
||||
BOOST_PARAMETER_NAME(arg1)
|
||||
|
||||
struct somebody
|
||||
{
|
||||
BOOST_PARAMETER_MEMBER_FUNCTION(
|
||||
(void), static f, tag, (optional (arg1,(int),0)))
|
||||
{
|
||||
std::cout << arg1 << std::endl;
|
||||
}
|
||||
};
|
||||
10
test/literate/template-keywords0.cpp
Normal file
10
test/literate/template-keywords0.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
namespace boost { namespace python {
|
||||
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable)
|
||||
|
||||
}}
|
||||
11
test/literate/template-keywords1.cpp
Normal file
11
test/literate/template-keywords1.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace tag { struct class_type; } // keyword tag type
|
||||
template <class T>
|
||||
struct class_type
|
||||
: parameter::template_keyword<tag::class_type,T>
|
||||
{};
|
||||
|
||||
}}
|
||||
38
test/literate/top-level0.cpp
Normal file
38
test/literate/top-level0.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
#include <boost/parameter.hpp>
|
||||
|
||||
namespace test
|
||||
{
|
||||
BOOST_PARAMETER_NAME(title)
|
||||
BOOST_PARAMETER_NAME(width)
|
||||
BOOST_PARAMETER_NAME(titlebar)
|
||||
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(int), new_window, tag, (required (title,*)(width,*)(titlebar,*)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(deleter)
|
||||
BOOST_PARAMETER_TEMPLATE_KEYWORD(copy_policy)
|
||||
|
||||
template <class T> struct Deallocate {};
|
||||
struct DeepCopy {};
|
||||
|
||||
namespace parameter = boost::parameter;
|
||||
|
||||
struct Foo {};
|
||||
template <class T, class A0, class A1>
|
||||
struct smart_ptr
|
||||
{
|
||||
smart_ptr(Foo*);
|
||||
};
|
||||
}
|
||||
using namespace test;
|
||||
int x =
|
||||
new_window("alert", _width=10, _titlebar=false);
|
||||
|
||||
smart_ptr<
|
||||
Foo
|
||||
, deleter<Deallocate<Foo> >
|
||||
, copy_policy<DeepCopy> > p(new Foo);
|
||||
43
test/literate/writing-the-function0.cpp
Normal file
43
test/literate/writing-the-function0.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#include <boost/parameter/name.hpp>
|
||||
|
||||
BOOST_PARAMETER_NAME(graph)
|
||||
BOOST_PARAMETER_NAME(visitor)
|
||||
BOOST_PARAMETER_NAME(root_vertex)
|
||||
BOOST_PARAMETER_NAME(index_map)
|
||||
BOOST_PARAMETER_NAME(color_map)
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class T = int>
|
||||
struct dfs_visitor
|
||||
{};
|
||||
|
||||
int vertex_index = 0;
|
||||
|
||||
}
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
|
||||
namespace graphs
|
||||
{
|
||||
BOOST_PARAMETER_FUNCTION(
|
||||
(void), // 1. parenthesized return type
|
||||
depth_first_search, // 2. name of the function template
|
||||
|
||||
tag, // 3. namespace of tag types
|
||||
|
||||
(required (graph, *) ) // 4. one required parameter, and
|
||||
|
||||
(optional // four optional parameters, with defaults
|
||||
(visitor, *, boost::dfs_visitor<>())
|
||||
(root_vertex, *, *vertices(graph).first)
|
||||
(index_map, *, get(boost::vertex_index,graph))
|
||||
(in_out(color_map), *,
|
||||
default_color_map(num_vertices(graph), index_map) )
|
||||
)
|
||||
)
|
||||
{
|
||||
// ... body of function goes here...
|
||||
// use graph, visitor, index_map, and color_map
|
||||
}
|
||||
}
|
||||
2
test/macros.cpp
Executable file → Normal file
2
test/macros.cpp
Executable file → Normal file
@@ -52,6 +52,6 @@ int main()
|
||||
, index = boost::ref(x), name = "foo"
|
||||
);
|
||||
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
0
test/maybe.cpp
Executable file → Normal file
0
test/maybe.cpp
Executable file → Normal file
0
test/mpl.cpp
Executable file → Normal file
0
test/mpl.cpp
Executable file → Normal file
0
test/normalized_argument_types.cpp
Executable file → Normal file
0
test/normalized_argument_types.cpp
Executable file → Normal file
0
test/ntp.cpp
Executable file → Normal file
0
test/ntp.cpp
Executable file → Normal file
0
test/optional_deduced_sfinae.cpp
Executable file → Normal file
0
test/optional_deduced_sfinae.cpp
Executable file → Normal file
4
test/preprocessor.cpp
Executable file → Normal file
4
test/preprocessor.cpp
Executable file → Normal file
@@ -453,7 +453,7 @@ int main()
|
||||
, name = S("foo")
|
||||
);
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
assert(sfinae("foo") == 1);
|
||||
assert(sfinae(1) == 0);
|
||||
|
||||
@@ -477,6 +477,6 @@ int main()
|
||||
, test::index = 2
|
||||
);
|
||||
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
0
test/preprocessor_deduced.cpp
Executable file → Normal file
0
test/preprocessor_deduced.cpp
Executable file → Normal file
1
test/python_test.cpp
Executable file → Normal file
1
test/python_test.cpp
Executable file → Normal file
@@ -2,6 +2,7 @@
|
||||
// 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)
|
||||
|
||||
#include <math.h>
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/parameter/preprocessor.hpp>
|
||||
#include <boost/parameter/keyword.hpp>
|
||||
|
||||
6
test/sfinae.cpp
Executable file → Normal file
6
test/sfinae.cpp
Executable file → Normal file
@@ -9,7 +9,7 @@
|
||||
#include <string>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
# include <boost/utility/enable_if.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
#endif
|
||||
@@ -70,7 +70,7 @@ namespace test
|
||||
f_impl(args(a0, a1));
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
// On compilers that actually support SFINAE, add another overload
|
||||
// that is an equally good match and can only be in the overload set
|
||||
// when the others are not. This tests that the SFINAE is actually
|
||||
@@ -96,7 +96,7 @@ int main()
|
||||
f("foo", 3.f);
|
||||
f(value = 3.f, name = "foo");
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
BOOST_TEST(f(3, 4) == 0);
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
|
||||
0
test/singular.cpp
Executable file → Normal file
0
test/singular.cpp
Executable file → Normal file
0
test/timings.txt
Executable file → Normal file
0
test/timings.txt
Executable file → Normal file
0
test/tutorial.cpp
Executable file → Normal file
0
test/tutorial.cpp
Executable file → Normal file
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user