Since the first post, 229 commits went into the public repo as one merge. Five new modules, the rest of the text module, a new namespace layout, and a review of the whole API. Everything below is on main now.
New modules
- time: Go's
timepackage in C++.sgcl::durationlives in core, because the timers take one. It reads and writes Go's text ("1h30m0.5s"), and everystd::chronoduration converts to it.- Calendar dates use the Euclidean affine functions of Neri and Schneider. Time zones come from the system's tz database.
- Layouts work in both Go's and strftime's notation, and
txt::formatunderstands the<chrono>types. - Measured against Go and
std::format.
- hash:
- the CRC family, Adler-32 and FNV;
- XXH3 64 and 128, written from the algorithm's description;
- SipHash;
- one interface, so a stream can be written into any of them.
- math:
big_integerandrational, as in Go'smath/big: Karatsuba, Toom-3 and Burnikel–Ziegler, plus number theory (pow,mod_pow,gcd,mod_inverse,sqrt,is_probable_prime);random, the same ChaCha8 stream as Go'smath/rand/v2.
- encoding:
- hex, base32, base64, ascii85, varint and PEM;
- JSON (RFC 8259) with a token reader, an immutable value, a writer, and typed reading and writing of your own types described by their fields;
- CSV as Go's
encoding/csvreads it; - XML with namespaces, a token reader, a tree and the same typed form.
- net:
- TCP, UDP and DNS on the reactor;
- a URL parser following the WHATWG URL Standard, checked against the web platform tests;
- HTTP/1.1: a client with a connection pool and redirects, and a server with Go 1.22-style routes.
net::http::server server; server.route("GET /hello/{name}", [](net::http::request req, net::http::response_writer w) { w.set_header("Content-Type", "text/plain"); w.write("hello, " + req.path_value("name") + "\n"); }); auto listener = net::tcp::listen("127.0.0.1:0"); auto serving = async::spawn(server.async_serve(*listener)); net::http::client client; auto res = client.get("http://127.0.0.1:" + to_string(listener->local_endpoint().port()) + "/hello/world");
txt grows
- Regular expressions in linear time, RE2-style: no backreferences and no lookaround, which is the price of that guarantee. A prefilter takes a literal search from 24.6 ns to 0.039 ns per byte.
- IDNA 2008, with punycode and percent encoding.
- A template engine, checked against Go's
text/template. - Collation: the fourth strength level of the collator, and a search that agrees with it.
Breaking changes
- A directory is a namespace:
sgcl::io,sgcl::async,sgcl::concurrent… Only core stays flat. The containers moved into core, and the immutable ones intosgcl::immutable. - io is synchronous by default, with
async_forms for tasks. Streams are checked structurally, andio::reader/io::writerare one-word handles over any stream. - Every function that can fail returns
expected<T, E>with amessage(). - Every wait in async has one form: an operation or a completion object, waited for with
co_awaitor.wait(). - Public constants are snake_case, as in
std(config::page_size,config::workers). Names are consistent across modules, and internal details moved out of the public classes.
The API was then audited by a second reviewer and checked twice. The bugs the audit found (a once whose body throws, a URL setter, a formatter, a read at the end of a stream) were each fixed with a test.
The collector
In debug builds, the check that warns when a pointer shares its word with data no longer reports two false alarms: an owner stored next to a raw pointer into what it owns, and data that happens to point inside an object.
Still true
Tested only on macOS / Apple Silicon so far. Linux and Windows are pending.
Next
compress, crypto (with TLS 1.3), then the rest of net (TLS, HTTP/2), serialization of object graphs, and codec.
- Repo: https://github.com/pebal/sgcl
- Module overview: https://github.com/pebal/sgcl#modules
Source: r/sgcl · by /u/pebalx