Skip to content

Use of non-existent member type on range-based append on string_builder #2543

@mrizaln

Description

@mrizaln

Describe the bug

string_builder uses type_value member type to get the value type of a range when checking whether it is a pair, but that is not correct which leads to compile time error. Not all ranges has value_type as its member type (for example transform_view). The correct way to to do this is using std::ranges::ranges_value_t.

To Reproduce

The code below will fail to compile at line 16:

#include <simdjson.h>
#include <print>

struct Foo
{
    int   a;
    float b;
};

int main()
{
    auto vec     = std::vector<Foo>{ { 1, 2.0f }, { 3, 4.0f }, { 5, 6.0f }, { 7, 8.0f } };
    auto builder = simdjson::builder::string_builder{};

    builder.start_object();
    builder.append_key_value<"vec">(vec | std::views::transform(&Foo::b));   // << here
    builder.end_object();

    std::println("{}", builder.view().take_value());
}

simjson release

master

Indicate whether you are willing or able to provide a bug fix as a pull request

sure

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions