import re


def get_cxx_function_begin_regex(name, static=False, template=None):
###############################################################################
    """
    >>> bool(get_cxx_function_begin_regex("fake_sub").match("void fake_sub("))
    True
    >>> bool(get_cxx_function_begin_regex("fake_sub").match("void fake_sub_2("))
    False
    >>> bool(get_cxx_function_begin_regex("fake_sub").match("  void  fake_sub ("))
    True
    >>> bool(get_cxx_function_begin_regex("fake_sub").match("  void  fake_sub ( one, two )"))
    True
    >>> bool(get_cxx_function_begin_regex("fake_sub").match("// void fake_sub("))
    False
    >>> bool(get_cxx_function_begin_regex("fake_sub").match("void fake_sub"))
    False
    >>> bool(get_cxx_function_begin_regex("fake_sub", static=True).match("static void fake_sub("))
    True
    >>> bool(get_cxx_function_begin_regex("fake_sub", template="Foo<T>").match("void Foo<T>::fake_sub("))
    True
    """
    static_regex_str = r"static\s+" if static else ""
    template_regex_str = r"{}::".format(template) if template else ""
    function_begin_regex_str = r"^\s*{}void\s+{}{}\s*[(]".format(static_regex_str, template_regex_str, name)
    return re.compile(function_begin_regex_str)