Giter VIP home page Giter VIP logo

Comments (6)

akonskarm avatar akonskarm commented on August 31, 2024 1

Yes, also because some compiler versions support only <experimental/string_view> and newer ones have <string_view>

The code below worked for me

BETTER_ENUMS_CONSTEXPR_ inline bool _names_match(const char *stringizedName,
                                                 std::experimental::string_view &referenceName,
                                                 std::size_t index = 0)
{
    return
        _ends_name(stringizedName[index]) ? index == referenceName.size() :
        index == referenceName.size() ? false :
        stringizedName[index] != referenceName[index] ? false :
        _names_match(stringizedName, referenceName, index + 1);
}

    BETTER_ENUMS_CONSTEXPR_ static _optional                                    \
    _from_string_nothrow(std::experimental::string_view s);                     \
\
    BETTER_ENUMS_CONSTEXPR_ static _optional_index                              \
    _from_string_loop(std::experimental::string_view &s, std::size_t index = 0);\

BETTER_ENUMS_CONSTEXPR_ inline Enum::_optional_index                            \
Enum::_from_string_loop(std::experimental::string_view &s, std::size_t index)   \
{                                                                               \
    return                                                                      \
        index == _size() ? _optional_index() :                                  \
        ::better_enums::_names_match(                                           \
            BETTER_ENUMS_NS(Enum)::_raw_names()[index], s) ?                    \
            _optional_index(index) :                                            \
            _from_string_loop(s, index + 1);                                    \
}                                                                               \
\
BETTER_ENUMS_CONSTEXPR_ inline Enum::_optional                                  \
Enum::_from_string_nothrow(std::experimental::string_view s)                    \
{                                                                               \
    return                                                                      \
        ::better_enums::_map_index<Enum>(                                       \
            BETTER_ENUMS_NS(Enum)::_value_array, _from_string_loop(s));         \
}

from better-enums.

aantron avatar aantron commented on August 31, 2024

Hi :)

I've looked at it briefly, and it seems like a good thing to add. I haven't had time to properly do it, though.

from better-enums.

aantron avatar aantron commented on August 31, 2024

One minor annoyance is it will probably need conditional compilation, based on compiler version and an override macro to force the overloads to be enabled for when the version detection does the wrong thing.

from better-enums.

aantron avatar aantron commented on August 31, 2024

Thanks for that.

I won't have the time to integrate it in the immediate future (because of all that conditional compilation testing that would be needed).

If you'd like to give it a try, you're welcome to open a PR and test in the Better Enums CI setup. I think it might need to be updated to use some more recent compilers in its build rows.

I'm not sure what to do about std::experimental. Is it right that that namespace is not forwards-compatible (I never knew whether it is or isn't, actually), or something in there is guaranteed to stay? If not, we would probably want to avoid it entirely, and support only compilers that have std::string_view.

from better-enums.

sdebionne avatar sdebionne commented on August 31, 2024

I am also interested in this feature. I think support for std::string_view is good enough. I might have a shot at this, is there anyone currently working on this feature request?

from better-enums.

aantron avatar aantron commented on August 31, 2024

Thanks. Not to my knowledge.

from better-enums.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.