Releases: JacksonAllan/CC
Global initialization fix
Version 1.4.3 merely fixes initialized to work in the global scope under all compilers, rather than just Clang.
Thanks go to @heather7283 for identifying the bug.
Clang warning fix
Version 1.4.2 merely fixes a unreachable-code-generic-assoc warning generated by splice and init_clone in recent versions of Clang.
Thanks again to @fonghou for identifying the issue.
macOS and C++23 compatibility fixes
Version 1.4.1 introduces the following fixes:
- It removes the dependency on
uchar.hbecause this standard library header is missing on some platforms (namely macOS). - It removes some superfluous code causing a
-Wunreachable-code-generic-assocwarning on recent versions of Clang. - It corrects two minor issues that could obstruct compilation in C++, particularly C++23.
Special thanks go to @fonghou for identifying the uchar.h issue and helping to fix it.
Strings!
Version 1.4.0 is now available! The following is a summary of the new features:
Strings
This version adds the long-promised dynamic, null-terminated strings. A few aspects make CC strings unique:
CC strings support most character types
CC strings can be declared with char, unsigned char, signed char, char8_t (in C23), char16_t, or char32_t as their underlying element type:
str( char ) our_ascii_str;
str( unsigned char ) our_unsigned_ascii_str;
str( signed char ) our_signed_ascii_str;
str( char8_t ) our_utf8_str;
str( char16_t ) our_utf16_str;
str( char32_t ) our_utf32_str;CC provides a simple yet powerful string-building API
For string manipulation, CC provides the push_fmt and insert_fmt variadic macros. These macros can be used to concatenate strings and append and insert other formatted data:
int foo = 10;
double bar = 20;
str( char ) our_str;
init( &our_str );
push_fmt( &our_str, "foo: ", foo, " bar: ", bar );
// our_str's content: "foo: 10 bar: 20.00".push_fmt and insert_fmt support regular C strings, CC strings, fundamental integer and floating point types, and several format manipulators for specifying number representation, precision, and minimum digits. For more details, see the README example and the API Reference.
CC strings are designed for easy interoperability with other CC containers
Default hash, comparison, and memory-freeing destructor functions are defined by default for all CC string types. Hence, they can be used as keys or elements of other CC containers out-of-the-box, with no boilerplate required from the user.
Additionally, when CC strings are used as the key and/or element type of another container, the library supports heterogeneous insertion and heterogeneous lookup. In other words, API macros that operate on the container may optionally take – as their key and/or element argument – a regular C string of the corresponding character type, rather than a CC string:
map( str( char ), str( char ) ) our_map;
init( &our_map );
insert( &our_map, "foo", "bar" ); // Heterogeneous insertion.
str( char ) *el = get( &our_map, "foo" ); // Heterogeneous lookup.For more details, see the README example.
Alternative initialization
This version also adds the initialized macro as an alternative means of initializing containers:
// Old initialization:
vec( int ) our_vec;
init( &our_vec );
// New initialization:
vec( int ) our_vec = initialized( &our_vec );The main purpose of initialized is to allow initialization of global containers at the site of their declaration. Previously, such containers had to be initialized elsewhere at runtime.
Default hash and comparison functions for const C strings
This version adds default hash and comparison functions for const C strings (i.e. const char *), eliminating the need for users to define their own functions for this type before it can be used as keys of maps and ordered maps or elements of sets and ordered sets.
Extended support for compiler warnings
This version adds support for the -Wextra and -Wconversion options in GCC and Clang.
Faster string hashing
This version introduces Wyhash for hashing both C and CC strings, replacing FNV-1a in the case of the former. Benchmarks proved Wyhash to be significantly faster than most of its competitors, especially the aforementioned FNV-1a.
With version 1.4.0, CC has now reached the milestone of including all the container types originally planned for it. See here for a discussion of the future direction of the library or here to sponsor 🩷 its ongoing development.
v1.4.0 Prerelease
Edit: Version 1.4.0 has now been fully released. Its release notes can be now found here.
Map cleanup destructor bug fix
Version 1.3.2 fixes a critical bug causing maps to call the wrong destructors during cleanup. This bug would affect users using destructors in conjunction with maps.
Linking bug fix
Version 1.3.1 patches a linking issue resulting from a static inline qualifier missing from one of the functions used internally by omap and oset. Thanks go to @gabewillen for identifying the bug.
Ordered maps and sets
Version 1.3.0 introduces ordered maps and ordered sets (omap and oset). These containers are implemented as red-black trees and perform on par with their C++ STL equivalents (benchmarks compiled with GCC 12.1 via MinGW-w64):
This version also fixes next and prev for lists to correctly handle an r_end and end pointer-iterator argument, respectively.
It also deprecates reverse iteration for unordered maps and sets (map and set) because next does not correctly handle an r_end pointer-iterator argument and cannot be changed to do so without an impact on forward iteration performance. Hence, using maps and sets with the API macros last, prev, and r_end now generates a compiler warning (in GCC and Clang) or error (in MSVC), which can be disabled by defining CC_ALLOW_DEPRECATED before the macros are called. This functionality will be removed entirely in the next release. Note that the newly introduced ordered maps and sets do support reverse iteration.
MSVC support
This version introduces support for MSVC version 19.39 and later, including support for MSVC's nonconformant preprocessor (which remains the default in C++ builds). MSVC users need only set the compiler's language standard to C11 or later, either by passing /std:c11 via the command line or setting the "C Language Standard" option in the project-properties dialog inside Visual Studio. This support was made possible by MSVC's recent introduction of typeof and the groundwork on CC's code done by @Hizuru3.
Map and set rehash bug fix
This version fixes a bug in map and set that could theoretically cause a crash when cc_shrink prompts a full-table rehash. The bug was reported in CC’s sister library, Verstable. In testing, I managed to trigger this bug using an (illegal) maximum load factor higher than 1.0.