File: init.qbk

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (91 lines) | stat: -rw-r--r-- 3,913 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
[section boost/python/init.hpp]
[section Introduction]
<boost/python/init.hpp> defines the interface for exposing C++ constructors to Python as extension class `__init__` functions.
[section init-expressions]
An init-expression is used to describe a family of `__init__` methods to be generated for an extension class, and the result has the following properties:
[variablelist
[[docstring][An [link ntbs] whose value will bound to the method's `__doc__` attribute]]
[[keywords][A [link function_invocation_and_creation.boost_python_args_hpp.introduction.keyword_expressions keyword-expression] which will be used to name (a trailing subsequence of) the arguments to the generated `__init__` function(s).]]
[[call_policies][An instance of a model of [link concepts.callpolicies CallPolicies].]]
[[argument_types][An MPL sequence of C++ argument types which will be used to construct the wrapped C++ object. An init expression has one or more valid prefixes which are given by a sequence of prefixes of its argument types.]]
]
[endsect]
[endsect]
[section Class template `init`]
A MPL sequence which can be used to specify a family of one or more __init__ functions. Only the last Ti supplied may be an instantiation of optional<...>.

``
namespace boost { namespace python
{
  template <T1 = unspecified,...Tn = unspecified>
  struct init
  {
    init(char const* doc = 0);
    template <class Keywords> init(Keywords const& kw, char const* doc = 0);
    template <class Keywords> init(char const* doc, Keywords const& kw);

    template <class CallPolicies>
    unspecified operator[](CallPolicies const& policies) const
  };
}}
``
[section Class template `init` constructors]
``
init(char const* doc = 0);
template <class Keywords> init(Keywords const& kw, char const* doc = 0);
template <class Keywords> init(char const* doc, Keywords const& kw);
``
[variablelist
[[Requires][If supplied, doc is an [link ntbs]. If supplied, kw is the result of a ]]
[[Effects][The result is an init-expression whose docstring is doc and whose keywords are a reference to kw. If the first form is used, the resulting expression's keywords are empty. The expression's call policies are an instance of [link function_invocation_and_creation.models_of_callpolicies.boost_python_default_call_polici default_call_policies]. If Tn is [link high_level_components.boost_python_init_hpp.class_template_optional optional<U1, U2,... Um>], the expression's valid prefixes are given by: ``(T1, T2,...Tn-1), (T1, T2,...Tn-1 , U1), (T1, T2,...Tn-1 , U1, U2), ...(T1, T2,...Tn-1 , U1, U2,...Um)``. 
Otherwise, the expression has one valid prefix given by the template arguments the user specified. ]]
]
[endsect]
[section Class template `init` observer functions]
``
template <class Policies>
unspecified operator[](Policies const& policies) const
``
[variablelist
[[Requires][Policies is a model of [link concepts.callpolicies CallPolicies].]]
[[Effects][Returns a new [link high_level_components.boost_python_init_hpp.introduction.init_expressions init-expression] with all the same properties as the init object except that its call policies are replaced by a reference to policies.]]
]
[endsect]
[endsect]
[section Class template `optional` ]
A MPL sequence which can be used to specify the optional arguments to an __init__ function.
``
namespace boost { namespace python
{
  template <T1 = unspecified,...Tn = unspecified>
  struct optional {};
}}
``
[endsect]
[section Example]
Given the C++ declarations:
``
class Y;
class X
{
 public:
   X(int x, Y* y) : m_y(y) {}
   X(double);
 private:
   Y* m_y;
};
``
A corresponing Boost.Python extension class can be created with:
``
using namespace boost::python;

class_<X>("X", "This is X's docstring.",
          init<int,char const*>(args("x","y"), "X.__init__'s docstring")[
                with_custodian_and_ward<1,3>()]
          )
   .def(init<double>())
   ;

``
[endsect]
[endsect]