Skip to content

<xstring>: conversion between basic_string specializations could sometimes memcpy #2901

@CaseyCarter

Description

@CaseyCarter

For example:

std::u8string x = "potato";
std::string a(x.begin(), x.end());
std::string b(x.data(), x.size());
std::string c(std::from_range, x);

could all be implemented with memcpy. At the very least, this should happen when initializing std::basic_string<char, std::char_traits<char>> from std::basic_string<T, std::char_traits<T>> when T is an integral type with size 1. More generally, I think this optimization could apply when the source and target element types are integral types of the same size and the target traits type is library-provided.

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