llmcpp-generated-templates
Table of Contents
Generated templates (llmcpp)
Generated templates request one reusable implementation expressed in terms of template parameters. The repository's top-k example specifies ordering and tie behavior:
template <typename Range, typename Projection> __llm__ auto top_k_by(const Range &values, std::size_t count, Projection project) -> std::vector<typename Range::value_type> { Return at most count elements from values with the greatest project value. Order results from greatest to least, preserving input order for ties. }
The body must use the supplied range and projection rather than assume a particular record type. The return type depends on Range::value_type, which Clang interprets as C++ syntax.
llmcpp generates one template body, not one body per instantiation. Candidate compilation checks what is visible and instantiated in the translation unit. Other argument types may expose errors later, so tests should cover the kinds of ranges and projections the interface promises to support.
Source: 11_top_k_by.cpp.
llmcpp-generated-templates.md · Last modified: by 127.0.0.1
