Date: Thu, 15 Feb 2024 20:30:37 +0000
The real-world demand for deserialization is too complex, and there are three main issues: 1. Where to and from? Using iostream will result in terrible performance, and so will non-contiguous iterators, so using std::span seems to be the only sensible solution, but it alone is not enough. 2. Is it extensible? Different serializers have their own unique behaviors, so if the standard library conflicts with them, users may not use the standard library. 3. How to implement it? JSON serialization is usually performance-sensitive, but high-performance JSON deserializers are very complex and may be difficult to implement. I can’t answer these questions, so I didn’t provide serialization and deserialization. However, I think that having a class in the standard library that represents the JSON is still positive. First, serializers and deserializers are usually easy to replace, even if they exist in the standard library, users may choose some implementations that better suit their needs; second, the standard library facilities have a demonstrative effect on the development of third-party libraries, the standard library has been establishing a series of conventions for more than 20 years, making it easier for users to switch between these libraries that meet the conventions, and reducing the learning cost (think of string_view). Therefore, some excellent facilities should not be affected by the lack of the standard library (think of coroutines and modules). Suppose C++ has a network library in the future, users may no longer be so eager for the standard library to provide a serialization and deserialization API, because the network library will handle it automatically; or suppose someone implements a new network library that can directly use the standard library’s JSON, instead of implementing it themselves or seeking a third-party library. If anyone wants to add some serialization/deserialization APIs that adapt to the existing facilities of the standard library (such as iostream, FILE*, format, filesystem), please speak up, and if you have any other ideas, please let me know.
Received on 2024-02-15 20:30:44