TMPPy is a subset of Python that can be compiled to C++ meta-functions using the py2tmp compiler. This project is aimed at C++ library developers whose libraries include a non-trivial amount of C++ metaprogramming.
Compared to writing C++ metaprogramming code directly, using TMPPy allows that code to be expressed in a more concise and readable way, provides static type checking (avoiding some classes of instantiation-time errors) and produces optimized C++ meta-functions, reducing the compile time for the C++ compilation.
Example
As an example, let’s write a metafunction (aka type trait class) add_pointer_multiple such that:
add_pointer_multiple<T, 0>::type is T
add_pointer_multiple<T, 1>::type is T*
add_pointer_multiple<T, 2>::type is T**
(and so on)
This can be written as a template, as follows:
template <typename T, int64_t n>
struct add_pointer_multiple {
using type = typename add_pointer_multiple<T, n - 1>::type*;
};
template <typename T>
struct add_pointer_multiple<T, 0> {
using type = T;
};
However this syntax is quite verbose and not very readable. For more complex metafunctions this becomes a significant issue, leading to more bugs and more effort when debugging or maintaining the code.
Some C++ metaprogramming libraries (notably Boost’s MPL library) can be used to reduce the verbosity, however that comes at the price of slower compile times.
Using TMPPy, the above can be written as:
def add_pointer_multiple(t: Type, n: int) -> Type:
if n == 0:
return t
else:
return Type('T*', T=add_pointer_multiple(t, n-1))
And this TMPPy code can then be compiled to C++ code equivalent to the metafunction above (without the overhead of e.g. MPL).
For more information on TMPPy, see the wiki.
License
TMPPy is released under the Apache 2.0 license. See the LICENSE file for details.
This is not an official Google product.
Metadata
Release files for TMPPy 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| TMPPy-0.1.3.tar.gz | 52.6 kB | Without provenance | Details for TMPPy-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| TMPPy-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for TMPPy-0.1.3-py3-none-any.whl |
Total release size: 114.6 kB
Release files / TMPPy-0.1.3.tar.gz
| Download URL | TMPPy-0.1.3.tar.gz |
|---|---|
| Size | 52.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
841ceb0352284c8ed166c03abd9df1d403d4c259a04f06fd49889beb426757c1
|
|
BLAKE2b-256 checksum How to use checksums |
92db22b144db5aa768287490cff32da93b72a5ee98716a88746b4a9534bff4bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / TMPPy-0.1.3-py3-none-any.whl
| Download URL | TMPPy-0.1.3-py3-none-any.whl |
|---|---|
| Size | 62.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91ee12409478a515e234109af91d0007ce3cdf634b359aa545805b2d5adaae8f
|
|
BLAKE2b-256 checksum How to use checksums |
b34762a89bf5ad12147349897ddcca808a464e022342d640b0576182770bddef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for TMPPy 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.