Core containers
AK provides efficient, modern C++ containers designed for browser development.Vector
Vector<T> is a dynamic array similar to std::vector but with Ladybird-specific optimizations:
append()- Add element to endprepend()- Add element to beginninginsert()- Insert at specific indexremove()- Remove by indexfind()- Search for elementsize()- Get element count
HashMap
HashMap<K, V> provides hash-based key-value storage:
Other containers
HashTable
Hash-based set for unique values
Optional
Type-safe nullable value wrapper
Variant
Type-safe union holding one of several types
Span
Non-owning view over contiguous data
Smart pointers
AK includes three main smart pointer types for memory safety.OwnPtr and NonnullOwnPtr
Single-owner pointers for exclusive ownership:NonnullOwnPtr cannot be null, making it perfect for return types and parameters where null is invalid. It’s equivalent to passing by reference (&) but with ownership transfer.RefPtr and NonnullRefPtr
Reference-counted pointers for shared ownership:WeakPtr
Non-owning pointer that automatically becomes null when the target is deleted:String types
AK provides multiple string types optimized for different use cases.String
UTF-8 encoded, reference-counted string with short string optimization:String can store short strings (up to 23 bytes) inline without heap allocation, making it very efficient for common use cases.StringView
Non-owning view over string data:StringBuilder
Efficient string building through concatenation:Error handling
ErrorOr<T>
Type-safe error handling without exceptions:Result<T, E>
Generic result type for operations that can fail:String formatting
AK providesprintf-style formatting with compile-time checking.
Type specifiers
b binary, d decimal, x hex, s string, p pointerAlignment
< left, > right, ^ centerWidth & precision
{:10} min width, {:.4} precision/maxUtilities
Function
Type-erased callable wrapper:Time
High-resolution time with duration types:Badge
Restrict function access to specific classes:Source location
- Repository:
~/workspace/source/AK/ - Key headers:
Vector.h,HashMap.h,String.h,NonnullOwnPtr.h,RefPtr.h,Optional.h - Documentation:
~/workspace/source/Documentation/SmartPointers.md,~/workspace/source/Documentation/StringFormatting.md