Dan Eble <d...@faithful.be> writes: > On Feb 10, 2020, at 20:48, David Kastrup <d...@gnu.org> wrote: >> >> Templating on a string constant is, unfortunately, not a thing at least >> in C++11 (don't know whether they managed since then). Or one could go >> that route rather than GCC-specific in-expression use of a static >> initializer. > > Well, constexpr enables some new and interesting things, though I > imagine that having to interact with Guile nixes them.
For the purpose of generating a near-compile-time constant that would not be a problem, static initialization to the win. Like template <const char *symbol> SCM make_symbol () { static SCM sym = scm_permanent_object (scm_string_to_symbol (symbol)); return sym; } which would generate one function per symbol that on its _first_ call (when the Guile subsystem is already active) converts the symbol into SCM and then memoizes it. But as far as I know, C++11 cannot template on string constants (C or C++) like that. You need to create a named character array or pointer and then can template on _that_ and that's a lot more cumbersome in practice. > Here, someone has figured out how to compute a CRC of a literal string > at compile time: https://stackoverflow.com/a/9842857 We would not need anything that complicated. -- David Kastrup My replies have a tendency to cause friction. To help mitigating damage, feel free to forward problematic posts to me adding a subject like "timeout 1d" (for a suggested timeout of 1 day) or "offensive".