Skip to content

Use std::string_view instead of std::string when string constant are generated #203

@Hsilgos

Description

@Hsilgos

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions