Thanks to visit codestin.com
Credit goes to github.com

Skip to content

std::swap of arrays, why is there no specialization for trivial types #2683

@monamimani

Description

@monamimani

I was looking at what swap was doing for arrays and in the MSVC stl it loops trough the array and swap each element. (libstdc++ and libc++ do the same thing).

The thing is, it was an array of std::byte, I was surprised that none of the STL have specializations for trivially copyable/movable types that would call memcopy. Now I figure, this is maybe how the spec is. So my first question is there something preventing those specialization from existing.

My second question which is maybe off-topic for this is even tough clang and gcc also do a loop, "I believe" their auto vectorizer see the pattern and emits SSE instructions but MSVC doesn't it still loops.

Here is a compiler explorer link
https://godbolt.org/z/W8GxPv1ov

Now this is maybe something more for the compiler team, I don't know.
In any case I saw the differences and I thought I would point it out.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedSomething works now, yay!performanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions