From 8a404e2d675d467cd16fb46b0935a18ac6439e2d Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 25 Nov 2007 18:38:02 +0000 Subject: [PATCH] Full merge from trunk at revision 41356 of entire boost-root tree. [SVN r41370] --- doc/html/python.html | 84 +++++++++++++++++++++++-------------------- doc/python.rst | 27 ++++++++------ test/basics.cpp | 2 +- test/basics.hpp | 7 ++-- test/preprocessor.cpp | 2 +- test/sfinae.cpp | 6 ++-- 6 files changed, 71 insertions(+), 57 deletions(-) diff --git a/doc/html/python.html b/doc/html/python.html index 20fcdd2..5e26f13 100644 --- a/doc/html/python.html +++ b/doc/html/python.html @@ -7,7 +7,7 @@ The Boost Parameter Library Python Binding Documentation - + @@ -25,7 +25,7 @@ Organization: Boost Consulting Date: -2006-09-21 +2006-12-14 Copyright: Copyright David Abrahams, Daniel Wallin 2005. Distributed under the Boost Software License, @@ -42,19 +42,19 @@ functions, operators and constructors to Python.

Contents

-

Introduction

+

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 @@ -81,7 +81,7 @@ We will take a closer look at how this is done in the tutorial section below.

-

Tutorial

+

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.

@@ -124,7 +124,8 @@ Python we use the binding utility 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.

+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
 {
@@ -188,7 +189,9 @@ forwarding overloads that we defined earlier. The second one is an 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.

+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.


-

concept ParameterSpec

+

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:

@@ -261,11 +264,12 @@ the arity range of mpl::vector2<x(int),y**(int)> is [1,2].

-

special keywords

+

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. 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:

+based on the presence of a parameter. For example:

+
 namespace core
 {
@@ -313,19 +317,21 @@ int main()
     depth_first_search(params()(color = 0));
 }''') -->
 
+
 

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. 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 2N, where N is the number of special keywords.

+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 2N, where N is the number of special keywords.


-

class template init

+

class template init

Defines a named parameter enabled constructor.

 template <class ParameterSpecs>
@@ -348,7 +354,7 @@ model of ParameterSpec.

  • For every N in [U,V], where [U,V] is the arity range of ParameterSpecs, Class must support these expressions:

    - +
    @@ -382,7 +388,7 @@ expressions:

    uses CallPolicies when creating the binding.

    -

    Example

    +

    Example

     #include <boost/parameter/keyword.hpp>
     #include <boost/parameter/preprocessor.hpp>
    @@ -441,7 +447,7 @@ assert(args[y | 1] == 1);
     

    -

    class template call

    +

    class template call

    Defines a __call__ operator, mapped to operator() in C++.

     template <class ParameterSpecs>
    @@ -464,7 +470,7 @@ is the result type of c(…)
     
  • Class must support these expressions, where c is an instance of Class:

    -
  • +
    @@ -494,12 +500,12 @@ instance of Class:

    -

    template <class CallPolicies> operator[](CallPolicies const&)

    +

    template <class CallPolicies> operator[](CallPolicies const&)

    Returns a def_visitor equivalent to *this, except that it uses CallPolicies when creating the binding.

    -

    Example

    +

    Example

     #include <boost/parameter/keyword.hpp>
     #include <boost/parameter/preprocessor.hpp>
    @@ -568,7 +574,7 @@ return 0;
     

    -

    class template function

    +

    class template function

    Defines a named parameter enabled member function.

     template <class Fwd, class ParameterSpecs>
    @@ -588,7 +594,7 @@ is the result type of c.f(…)
     
     
  • An instance of Fwd must support this expression:

    -
  • +
    @@ -620,7 +626,7 @@ are tagged arguments.

    -

    Example

    +

    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.

    @@ -684,7 +690,7 @@ assert(y == 1);

    -

    function template def

    +

    function template def

    Defines a named parameter enabled free function in the current Python scope.

     template <class Fwd, class ParameterSpecs>
    @@ -699,7 +705,7 @@ except the first models ParameterSpec. The first el
     is the result type of f(…), where f is the function.

  • An instance of Fwd must support this expression:

    -
  • +
    @@ -729,7 +735,7 @@ is the result type of f(…)
    -

    Example

    +

    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.

    @@ -766,14 +772,14 @@ BOOST_PYTHON_MODULE(…)
    -

    Portability

    +

    Portability

    The Boost.Parameter Python binding library requires partial template specialization.

    diff --git a/doc/python.rst b/doc/python.rst index 816369a..d70d917 100755 --- a/doc/python.rst +++ b/doc/python.rst @@ -132,7 +132,8 @@ Python we use the binding utility ``boost::parameter::python::function``. and pass to ``boost::python::class_::def()``. To use ``boost::parameter::python::function`` we first need to define -a class with forwarding overloads. +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. :: @@ -204,7 +205,9 @@ 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``. +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 @@ -295,8 +298,10 @@ the **arity range** of ``mpl::vector2`` is ``[2,2]`` and the 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. 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: +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:: @@ -351,18 +356,20 @@ docs. The example uses a different technique, but could also have been written l .. @build() -.. _example: index.html#dispatching-based-on-the-presence-of-a-default +.. .. _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. 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. +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. ------------------------------------------------------------------------------ diff --git a/test/basics.cpp b/test/basics.cpp index 98c333d..e5fb748 100755 --- a/test/basics.cpp +++ b/test/basics.cpp @@ -107,6 +107,6 @@ int main() //f(index = 56, name = 55); // won't compile - return 0; + return boost::report_errors(); } diff --git a/test/basics.hpp b/test/basics.hpp index 9407a1c..a2857e0 100755 --- a/test/basics.hpp +++ b/test/basics.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace test { @@ -79,9 +80,9 @@ struct values_t BOOST_MPL_ASSERT((boost::is_same)); BOOST_MPL_ASSERT((boost::is_same)); #endif - BOOST_ASSERT(equal(n, n_)); - BOOST_ASSERT(equal(v, v_)); - BOOST_ASSERT(equal(i, i_)); + BOOST_TEST(equal(n, n_)); + BOOST_TEST(equal(v, v_)); + BOOST_TEST(equal(i, i_)); } Name const& n; diff --git a/test/preprocessor.cpp b/test/preprocessor.cpp index ae44e4f..792a1b7 100755 --- a/test/preprocessor.cpp +++ b/test/preprocessor.cpp @@ -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); diff --git a/test/sfinae.cpp b/test/sfinae.cpp index c86d336..f017a21 100755 --- a/test/sfinae.cpp +++ b/test/sfinae.cpp @@ -9,7 +9,7 @@ #include #include -#ifndef BOOST_NO_SFINAE +#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592)) # include # include #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();