Giter VIP home page Giter VIP logo

Comments (6)

spreadsort avatar spreadsort commented on June 10, 2024

Done. It wasn't as simple to implement as you suggested, as string_sort requires an unsigned wchar_t, but it works now by splitting the wrapper into 2 enable_ifs, each with its own unsigned character type (wchar_t is signed).

from sort.

Morwenn avatar Morwenn commented on June 10, 2024

Ok, I didn't know about the unsigned wchar_t. To be honest, the library I am writing is 90% indirection & code architecture and 10% actual sorting logic if we exclude the algorithms that I didn't write, so I don't understand how some of the algorithms work (including this one), hence the bad suggestion, sorry for that.

Anyway, I didn't have many tests for std::wstring but they are passing with this fix. Thanks :)

from sort.

spreadsort avatar spreadsort commented on June 10, 2024

You're welcome.

from sort.

Morwenn avatar Morwenn commented on June 10, 2024

Oops, seems that I spoke too soon. For some reason I totally missed a warning introduced by the fix:

With g++:

warning: long, short, signed or unsigned used invalidly for 'unused' [-Wpedantic]

With clang++:

warning: 'wchar_t' cannot be signed or unsigned [-Wpedantic]

It seems like wchar_t shouldn't be declared unsigned, and it's true that its signedness is undefined by the standard. Would std::make_unsigned<wchar_t>::type (or a Boost equivalent) solve the problem?

from sort.

spreadsort avatar spreadsort commented on June 10, 2024

On Sun, Sep 20, 2015 at 8:06 AM Morwenn [email protected] wrote:

Oops, seems that I spoke too soon. For some reason I totally missed a
warning introduced by the fix:

With g++:

warning: long, short, signed or unsigned used invalidly for 'unused'
[-Wpedantic]

With clang++:

warning: 'wchar_t' cannot be signed or unsigned [-Wpedantic]

It seems like wchar_t shouldn't be declared unsigned, and it's true that
its signedness is undefined by the standard. Would
std::make_unsigned<wchar_t>::type (or a Boost equivalent) solve the
problem?

While resolving this issue, I ran into another complication I'd forgotten
about: wchar_t is 2 bytes on Windows, and 4 bytes on linux. 2 bytes sorts
nicely with the string_sort approach, but 4 bytes requires breaking up the
characters into pieces and feeding them to the algorithm, a bit of
complication I'm not ready to stick into the core library. Internally
string_sort handles characters of over 2 bytes that aren't being managed by
custom functors by just falling back to std::sort and issuing a
compile-time warning.

So my solution was:
Enable spreadsort for 2-byte wstrings (using uint16_t as the unsigned
character type), and update the documentation to make it clear that it
doesn't work for 4-byte wstrings. I've rolled this change out to master,
and reverted my wstring testing change, as testing std::sort of wstring
vectors on linux is just silly.

Bottom line: sorting wstrings with spreadsort on linux just isn't going to
work for you unless you're willing to write your own functors. For your
application, I think just skipping spreadsort wstring support should be
fine.

from sort.

Morwenn avatar Morwenn commented on June 10, 2024

Ok, I think I understand the problem a bit better, thanks for the explanation. I guess I'll just skip the std::wstring support for now as you suggest, or SFINAE it out when the character width is greater than 2 bytes.

from sort.

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.