Skip to content

Conversation

Copy link

Copilot AI commented Dec 1, 2025

Enables user-defined types (UDTs) to work in value_ref initializer lists by routing non-native types through value_from conversion.

Previously, UDTs with tag_invoke overloads for value_from_tag could not be used directly in array/object initializer lists because value_ref::from_const and from_rvalue only supported types with native value constructors.

Changes

  • value_ref.hpp: Added is_native_value_type<T> trait identifying types with direct value constructors (JSON types, numerics, string-like, nullptr)
  • impl/value_ref.hpp: Tag dispatch in from_const_impl and from_rvalue_impl to use value_from() for non-native types
  • test/value_ref.cpp: Tests for UDTs in initializer lists, object values, and nested structures

Example

struct Point { int x, y; };

void tag_invoke(value_from_tag, value& jv, Point const& p) {
    jv = { {"x", p.x}, {"y", p.y} };
}

// Now works:
Point p{1, 2};
array arr{p, 123};           // UDT in initializer
object obj{{"point", p}};    // UDT as object value
value jv = {{"data", {p}}};  // Nested UDTs

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Streamlined construction and assignment, and from UDTs</issue_title>
<issue_description>I think we should explore getting rid of most of the constructors and assignment operators in json::value and replace them with this

template< class T >
value( T&& t );

template< class T >
value& operator=( T&& t );

and in the same exploration, allow value_ref to type erase UDTs. This will allow jv( t.a ) and jv = t.a and jv = vec to work.

The way to do this is to add another constrained constructor to value_ref which accepts UDTs when a suitable tag_invoke exists, and then type erase it by storing a function pointer which, when invoked, calls tag_invoke with the storage_ptr and produces the json::value.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@vinniefalco @claude

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 1, 2025 17:59
Co-authored-by: vinniefalco <1503976+vinniefalco@users.noreply.github.com>
Co-authored-by: vinniefalco <1503976+vinniefalco@users.noreply.github.com>
Co-authored-by: vinniefalco <1503976+vinniefalco@users.noreply.github.com>
Co-authored-by: vinniefalco <1503976+vinniefalco@users.noreply.github.com>
Copilot AI changed the title [WIP] Streamline constructors and assignment for json::value Add UDT support to value_ref via value_from Dec 1, 2025
Copilot AI requested a review from vinniefalco December 1, 2025 18:32
Copilot finished work on behalf of vinniefalco December 1, 2025 18:32
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.72%. Comparing base (64db9b7) to head (98ba3c6).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1128      +/-   ##
===========================================
+ Coverage    93.71%   93.72%   +0.01%     
===========================================
  Files           91       91              
  Lines         9153     9168      +15     
===========================================
+ Hits          8578     8593      +15     
  Misses         575      575              
Files with missing lines Coverage Δ
include/boost/json/impl/value_ref.hpp 100.00% <100.00%> (ø)
include/boost/json/value_ref.hpp 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64db9b7...98ba3c6. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamlined construction and assignment, and from UDTs

2 participants