### Python Usage Example Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This Python code demonstrates how to use the bound `window` class and its `open` method after it has been exported via Boost.Python. It shows instantiation of the `window` object and calling the `open` method with named, optional parameters. ```python >>> w = my_module.window() >>> w.open(title = "foo", height = 20) ``` -------------------------------- ### C++ Example: Binding 'init' with Boost.Python and Boost.Parameter Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index A comprehensive C++ example demonstrating how to use Boost.Parameter's 'init' class template to bind a named-parameter constructor to Python using Boost.Python. It includes defining keywords, a base class, and the derived class 'X' with a specified constructor signature. ```cpp #include #include #include #include #include BOOST_PARAMETER_KEYWORD(tag, x) BOOST_PARAMETER_KEYWORD(tag, y) struct base { template 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", no_init) .def( py::init< mpl::vector >() ); } ``` -------------------------------- ### C++ Example: Binding a Constructor with init Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index An example demonstrating the use of `boost::parameter::python::init` to bind a C++ class constructor (`X`) to Python. It utilizes `BOOST_PARAMETER_CONSTRUCTOR` and `BOOST_PYTHON_MODULE` to define the class and its Python interface, specifying required and optional parameters with types. ```cpp #include #include #include #include #include BOOST_PARAMETER_KEYWORD(tag, x) BOOST_PARAMETER_KEYWORD(tag, y) struct base { template 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", no_init) .def( py::init< mpl::vector >() ); } ``` -------------------------------- ### Python Usage Example for a Bound Boost.Parameter Member Function Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This Python snippet shows how to instantiate the 'window' class exported from the C++ module and call its 'open' method. It demonstrates calling the 'open' function with keyword arguments for 'title' and 'height', utilizing the Boost.Parameter binding. ```python >>> w = my_module.window() >>> w.open(title = "foo", height = 20) ``` -------------------------------- ### Export Free Function with Named Parameters to Python Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This example demonstrates exporting a free function `f(int x, int y = ...)` to Python with named parameter support using the `def` function template. It creates a forwarding functor `f_fwd` that dispatches tagged arguments and uses the parameter specifications to define the function signature. ```cpp BOOST_PARAMETER_FUNCTION((void), f, tag, (required (x, *)) (optional (y, *, 1)) ) { _…_ } struct f_fwd { template void operator()(boost::type, 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"); } ``` -------------------------------- ### Exporting a Free Function to Python using boost::parameter::def (C++) Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ example demonstrates how to export a free function `f(int x, int y = ...)` to Python using `boost::parameter::def`. The `BOOST_PARAMETER_FUNCTION` macro defines the function with named parameter support. A forwarding struct `f_fwd` is provided to adapt the function call for Python, and `boost::parameter::def` is used within `BOOST_PYTHON_MODULE` to register the function in the Python scope. ```cpp BOOST_PARAMETER_FUNCTION((void), f, tag, (required (x, *)) (optional (y, *, 1)) ) { _…_ } struct f_fwd { template void operator()(boost::type, 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"); } ``` -------------------------------- ### Exporting a Member Function to Python using boost::parameter::python::function (C++) Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ example shows how to export a member function `f(int x, int y = ...)` of class `X` to Python. It utilizes `boost::parameter::python::function` to handle named parameters. The `BOOST_PARAMETER_MEMBER_FUNCTION` macro simplifies the definition of the member function with parameter specifications, and a forwarding struct `f_fwd` is used to adapt the call for Python. ```cpp #include #include #include #include #include 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 void operator()(boost::type, 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") .def("f", py::function< f_fwd , mpl::vector >() ); } ``` -------------------------------- ### Export Member Function with Named Parameters to Python Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This example demonstrates exporting a member function `f(int x, int y = ...)` to Python with named parameter support. It defines a forwarding functor `f_fwd` that handles the parameter dispatch and uses `py::function` to export the member function with specified parameter types and arity range. ```cpp #include #include #include #include #include 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 void operator()(boost::type, 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") .def("f", py::function< f_fwd , mpl::vector >() ); } ``` -------------------------------- ### C++ init Class Template for Constructors Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index Defines the `init` class template, a visitor for creating Python-bound constructors using named parameters. It requires `ParameterSpecs` to be an MPL sequence and details the C++ expressions `Class` must support. ```cpp template struct init : python::def_visitor > { template void def(Class& class_); template _def_visitor_ operator[](CallPolicies const& policies) const; }; ``` -------------------------------- ### Define Named Parameters with Boost.Parameter Keywords Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This snippet demonstrates how to define named parameter keywords using BOOST_PARAMETER_KEYWORD macro and configure parameter specifications with required and optional parameters. The code shows creating a class with operator() overloads that utilize the parameter framework to handle variable argument counts. ```cpp #include #include #include #include #include BOOST_PARAMETER_KEYWORD(tag, x) BOOST_PARAMETER_KEYWORD(tag, y) namespace parameter = boost::parameter; typedef parameter::parameters< parameter::required , parameter::optional > call_parameters; class X { public: template int call_impl(ArgumentPack const& args) { _… use args …_ } template int operator()(A0 const& a0) { return call_impl(call_parameters()(a0)); } template int operator()(A0 const& a0, A1 const& a1) { return call_impl(call_parameters()(a0,a1)); } }; ``` -------------------------------- ### C++ Tag Dispatching with Special Keywords Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index Demonstrates using a distinct default type (mpl::false_) for tag dispatching in C++ function overloads. It explains how to mark keywords as 'special' to generate the correct number of overloads (2^N) based on the count of special keywords. ```cpp #include namespace core { template void dfs_dispatch(ArgumentPack const& args, mpl::false_) { // ... compute and use default color map ... } template void dfs_dispatch(ArgumentPack const& args, ColorMap colormap) { // ... use colormap ... } } template void depth_first_search(ArgumentPack const& args) { core::dfs_dispatch(args, args[color | mpl::false_()]); } ``` -------------------------------- ### Define Boost.Parameter Keywords and a Class with an Enabled Member Function Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This C++ code defines keywords for 'title', 'width', and 'height' using BOOST_PARAMETER_KEYWORD. It then defines a 'window' class with a 'open' member function enabled by BOOST_PARAMETER_MEMBER_FUNCTION, specifying required and optional parameters with default values. ```cpp #include #include #include #include // 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 …_ } }; ``` -------------------------------- ### Boost.Python Module Export with Parameter Spec Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ code defines a Boost.Python module `my_module` and exports the `window` class. The `open` member function is bound using `boost::parameter::python::function`, which takes the forwarding overload class and an MPL vector specifying parameter types. Optional parameters are indicated with a `*`. ```cpp BOOST_PYTHON_MODULE(my_module) { using namespace boost::python; namespace py = boost::parameter::python; namespace mpl = boost::mpl; class_("window") .def( "open", py::function< open_fwd , mpl::vector< void , tag::title(std::string) , tag::width*(unsigned) , tag::height*(unsigned) > >() ); } ``` -------------------------------- ### Define Boost.Parameter Keywords and Class Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ code defines keywords and a class with a Boost.Parameter-enabled member function. The `BOOST_PARAMETER_KEYWORD` macro creates tags for named parameters, and `BOOST_PARAMETER_MEMBER_FUNCTION` simplifies the definition of functions with required and optional arguments. ```cpp #include #include #include #include // 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 …_ } }; ``` -------------------------------- ### Forwarding Overload for Boost.Python Binding Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ struct `open_fwd` provides a forwarding overload for the `window::open` member function. It's necessary because `window::open()` is a function template and Boost.Python requires a concrete function signature for binding. The `boost::type` parameter specifies the return type, and subsequent parameters match the function's arguments. ```cpp struct open_fwd { template void operator()( boost::type, window& self , A0 const& a0, A1 const& a1, A2 const& a2 ) { self.open(a0, a1, a2); } }; ``` -------------------------------- ### C++ Default Parameter Tag Dispatching with _special_ Keywords Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index Demonstrates how to use '_special_' keywords in C++ for default parameter values that differ in type from the parameter itself, enabling tag-dispatching. This technique is crucial when the default type is not convertible to the parameter type, allowing for distinct handling based on parameter presence. ```cpp namespace core { template void dfs_dispatch(ArgumentPack const& args, mpl::false_) { _…compute and use default color map…_ } template void dfs_dispatch(ArgumentPack const& args, ColorMap colormap) { _…use colormap…_ } } template void depth_first_search(ArgumentPack const& args) { core::dfs_dispatch(args, args[color | mpl::false_()]); } ``` -------------------------------- ### Export a Boost.Parameter Class and Member Function to Python Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This C++ code uses the BOOST_PYTHON_MODULE macro to define a Python module named 'my_module'. It then exports the 'window' class and its 'open' member function using boost::python::class_ and boost::parameter::python::function, specifying the function signature and parameter types. ```cpp BOOST_PYTHON_MODULE(my_module) { using namespace boost::python; namespace py = boost::parameter::python; namespace mpl = boost::mpl; class_("window") .def( "open", py::function< open_fwd , mpl::vector< void , tag::title(std::string) , tag::width*(unsigned) , tag::height*(unsigned) > >() ); } ``` -------------------------------- ### Exporting a Class with Member Function to Python (C++) Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ code snippet demonstrates how to export a class `X` with a member function `call_impl` to Python using Boost.Parameter and Boost.Python. It defines keywords, parameter packs, and uses `BOOST_PYTHON_MODULE` to create the Python binding. The `py::call` mechanism is used to bind the member function, specifying argument types and optional parameters. ```cpp #include #include #include #include #include BOOST_PARAMETER_KEYWORD(tag, x) BOOST_PARAMETER_KEYWORD(tag, y) namespace parameter = boost::parameter; typedef parameter::parameters< parameter::required , parameter::optional > call_parameters; class X { public: template int call_impl(ArgumentPack const& args) { _… use args …_ } template int operator()(A0 const& a0) { return call_impl(call_parameters()(a0)); } template 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") .def( py::call< mpl::vector >() ); } ``` -------------------------------- ### Understanding Boost.Parameter ParameterSpec and Arity Range Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This section explains the concept of 'ParameterSpec' in Boost.Parameter, which defines a keyword tag (K) and its argument type (T). It details how 'K' can be required ('Tag'), optional ('Tag*'), or special ('Tag**'), and how these relate to the arity range of an MPL Sequence of ParameterSpecs. ```text 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 `boost::parameter::keyword`. The **arity range** for an MPL Sequence of ParameterSpec's is defined as the closed range: ``` [ mpl::size - number of _special_ keyword tags in `S`, mpl::size ] ``` For example, the **arity range** of `mpl::vector2` is `[2,2]`, the **arity range** of `mpl::vector2` is `[2,2]` and the **arity range** of `mpl::vector2` is `[1,2]`. ``` -------------------------------- ### Create a Forwarding Overload for a Boost.Parameter Member Function Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This C++ code defines a forwarding struct 'open_fwd' with an 'operator()'. This operator is designed to be called by boost::python::function and dispatches the call to the actual 'window::open()' member function, handling parameter types and the 'self' object. ```cpp struct open_fwd { template void operator()( boost::type, window& self , A0 const& a0, A1 const& a1, A2 const& a2 ) { self.open(a0, a1, a2); } }; ``` -------------------------------- ### Export Named Parameter Class to Python with Boost.Python Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This snippet shows how to export a C++ class with named parameter support to Python using BOOST_PYTHON_MODULE. It uses the py::call template to define the parameter specifications including the return type and named parameters with their types. ```cpp BOOST_PYTHON_MODULE(_module name_) { using namespace boost::python; namespace py = parameter::python; namespace mpl = boost::mpl; class_("X") .def( py::call< mpl::vector >() ); } ``` -------------------------------- ### Define function Class Template for Named Parameter Member Functions Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/index This code defines the `function` class template structure that enables named parameter support for member functions exported to Python. The template accepts a forwarding functor and parameter specifications as MPL sequences, where the first element is the return type. ```cpp template struct function : python::def_visitor > { template void def(Class& class_, char const* name, Options const& options); }; ``` -------------------------------- ### C++ call Class Template for __call__ Operator Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index Defines the `call` class template, a visitor used to bind a C++ class's `operator()` to Python's `__call__` method. It specifies requirements for `ParameterSpecs` and the `Class` that must support callable expressions with tagged arguments. ```cpp template struct call : python::def_visitor > { template void def(Class& class_); template _def_visitor_ operator[](CallPolicies const& policies) const; }; ``` -------------------------------- ### ParameterSpec Concept and Arity Range Source: https://www.boost.org/doc/libs/latest/libs/parameter_python/doc/html/index This C++ code snippet explains the `ParameterSpec` concept in Boost.Parameter, which defines a keyword tag and its argument type. It details how required (`Tag`), optional (`Tag*`), and special (`Tag**`) keywords affect the function's arity range, which is the range of possible argument counts the function can accept. ```cpp // 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 `boost::parameter::keyword`. // The **arity range** for an MPL Sequence of ParameterSpec's is defined as the closed range: // ``` // [ mpl::size - number of _special_ keyword tags in `S`, mpl::size ] // ``` // // For example, the **arity range** of `mpl::vector2` is `[2,2]`, the **arity range** of `mpl::vector2` is `[2,2]` and the **arity range** of `mpl::vector2` is `[1,2]`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.