Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hsilgos opened this issue Mar 13, 2020 · 2 comments · May be fixed by #1444
Open

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

Hsilgos opened this issue Mar 13, 2020 · 2 comments · May be fixed by #1444
Assignees
Labels
c++ enhancement New feature or request

Comments

@Hsilgos
Copy link
Contributor

Hsilgos commented Mar 13, 2020

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.

@DanielKamkha DanielKamkha added c++ enhancement New feature or request labels Mar 13, 2020
@DanielKamkha
Copy link
Contributor

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.

@DanielKamkha DanielKamkha self-assigned this Aug 2, 2022
@DanielKamkha
Copy link
Contributor

Can be implemented now that Gluecodium fully supports C++17.

DanielKamkha added a commit that referenced this issue Aug 3, 2022
Resolves: #203
Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
@DanielKamkha DanielKamkha linked a pull request Aug 3, 2022 that will close this issue
DanielKamkha added a commit that referenced this issue Aug 18, 2022
Resolves: #203
Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
DanielKamkha added a commit that referenced this issue Aug 25, 2022
Resolves: #203
Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
DanielKamkha added a commit that referenced this issue Sep 1, 2022
Resolves: #203
Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
DanielKamkha added a commit that referenced this issue Sep 1, 2022
Resolves: #203
Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
DanielKamkha added a commit that referenced this issue Sep 5, 2022
Resolves: #203
Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants