Once a problem becomes a non-toy problem, pipelines lose.
troff(1) will do all the hyphenation (C or C++ code) in your code. Ironically troff is like TeX, it processes documents.
hyphen < input | layout | topostscript
where hyphen inserts all possible hyphens, and layout discards those which are unnecessary.