gluecodium
gluecodium copied to clipboard
Use std::string_view instead of std::string when string constant are generated
Assuming next declaration in lime:
struct Foo {
const BAR: String = "bar text"
}
Gluecodium generates struct with static const std::string fields:
struct Foo {
static const std::string BAR;
}
It leads to waisting of memory, warnings that constructor of std::string may throw an uncaught exception and undefined initialisation order in case when user code relies on those constants. Possible solution which may solve all these problems: use std::string_view from C++17. Gluecodium may generate something like this:
struct Foo {
constexpr std::string_view BAR = "bar text";
}
Also consider to generate to_string for enums using string_view.
This is a good suggestion. However, since Gluecodium supports C++11 and C++14 where std::string_view does not exist, this optimization needs to be controlled by a command line option.
Since we already have quite a mess of command line options, those need to be sorted out somehow. One possible approach would be to have structured per-language options, e.g. -cpp compatibility=17 namespace=foo
.
Can be implemented now that Gluecodium fully supports C++17.