To dedicate a creative work into the public domain, you need to
- be the copyright holder, and
- be subject to a jurisdiction that even has a concept of “public domain”.
If you include a function from another project, you are not the sole copyright holder, and are therefore unable to dedicate your project to the public domain.
However, you may be able to dedicate parts of your project into the public domain. To keep this maintainable, I strongly suggest that this isn't done on a function-by-function basis, but either
- by managing the license or public domain status individually for each file or folder in your project, and noting in your README that some parts are public domain whereas others are licensed,
- or by not including that function in your source code, and rather linking to the non-public-domain code at build time.
In any case, the resulting executable code will not be in the public domain.
A few general notes about public domain works:
As some jurisdictions (especially, civil-law countries) do not have a concept of “public domain”, consider adding a fallback license such as CC0. This fallback waives any copyright and related rights you may hold.
A public domain dedication does not release all rights you have in the project. Notably, patents and trademarks are not affected. Mature licenses such as Apache 2.0 or GPLv3 also include a patent grant to ensure that users cannot just copy the code, but also safely use it.