from typing import Optional


def build_cfn(
    ret: str,
    name: str,
    *,
    params: Optional[list[str]] = None,
    body: Optional[list[str]] = None,
    vret: Optional[str] = None,
) -> str:
    """Builds a Cpp function"""
    if body:
        body = ["  " + line for line in body]
    if ret == "string":
        ret = "std::string"
    return "\n".join(
        [
            # returntype functionName(type varname, for all params)
            f'{ret} {name}({", ".join(params or [])})',
            "{",  # {
            (";\n".join(body) + ";" if body else ""),  # function body
            (f"  return {vret};" if ret != "void" else ""),
            "};\n",  # return varname;  # };
        ]
    )