⇤ ← Revision 1 as of 2002-09-25 19:57:58
711
Comment:
|
717
Corrected explicit check code
|
Deletions are marked like this. | Additions are marked like this. |
Line 20: | Line 20: |
extractor<int> get_int(x); if (get_int) |
extract<int> get_int(x); if (get_int.check()) |
extractor interface which can be used to extract C++ types from Python objects.
We have discussed two main use cases for extractions
1. In user code which needs to retrieve C++ objects from their corresponding Python objects:
- Getting value:
void f(object x) { int y = extract<int>(x); // retrieve an int from x }
- Users may also want to explicitly check for convertibility:
int g(object x) { extract<int> get_int(x); if (get_int.check()) return get_int(); else return 0; }
2. In the implementation of sequence from_python converters (e.g. Python tuple/list -> std::vector)