MBO, a C++20 library: This C++20 library provides some general useful building blocks and integrates with Google's Abseil library.
APACHE-2.0 License
This C++20 library provides some general useful building blocks and integrates with Google's Abseil library.
The library is tested with Clang and GCC using continuous integration: . Manual testing with native Apple clang version 15.0.0 ARM is also done.
The C++ library is organized in functional groups each residing in their own directory.
namespace mbo::container
AnyScan
: A container type independent iteration view - or scan over the container.ConstScan
: A container type independent iteration view for const value_types.ConvertingScan
: A container scanner that allows for conversions.MakeAnyScan
: Helper function to create AnyScan
instances.MakeConstScan
: Helper function to create ConstScan
instances.MakeConvertingScan
: Helper function to create ConvertingScan
instances.ConvertContainer
simplifies copying containers to value convertible containers.LimitedMap
: A space limited, constexpr compliant map
.LimitedOptions
: A compile time configuration option for LimitedSet
and LimitedMap
.LimitedSet
: A space limited, constexpr compliant set
.LimitedVector
: A space limited, constexpr compliant vector
.namespace mbo::diff
UnifiedDiff
: A class that implements unified-diffing.unfied_diff
: A binary that performs a unified-diff on two files.difftest
: A test rule that compares an output versus a golden file.namespace mbo::files
Artefact
: Holds information about a file (its data content, name, and modified time).GetContents
: Reads a file and returns its contents or an absl::Status error.GetMTime
: Returns the last update/modified time of a file or an absl::Status error.GetMaxLines
: Reads at most given number of text lines from a file or returns absl::Status error.IsAbsolutePath
: Returns whether a given path is absolute.JoinPaths
: Join multiple path elements.JoinPathsRespectAbsolute
: Join multiple path elements respecting absolute path elements.NormalizePath
: Normalizes a path.Readable
: Returns whether a file is readable or an absl::Status error.SetContents
: Writes contents to a file.IniFile
: A simple INI file reader.namespace mbo::hash
simple::GetHash(std::string_view)
: A constexpr capable hash function.namespace mbo::log
mbo::log::LogTiming([args])
a simple timing logger.namespace mbo::mope
MOPE
templating engine. Run bazel run //mbo/mope -- --help
for detailed documentation.mope
.Template
: The mope template engine and data holder.ReadIniToTemplate
: Helper to initialize a mope Template from an INI file.mope
: A rule that expands a mope template file.mope_test
: A test rule that compares mope template expansion against golden files. Thisclang-format
and thus can be used for source-code generation and verification.namespace mbo::status
StatusBuilder
which allows to extend the message of an absl::Status
.GetStatus
allows to convert types to an absl::Status
.MBO_ASSIGN_OR_RETURN
: Macro that simplifies handling functions returning absl::StatusOr<T>
.MBO_MOVE_TO_OR_RETURN
: Macro that simplifies handling functions returning absl::StatusOr<T>
where the result requires commas, in particular structured bindings.MBO_RETURN_IF_ERROR
: Macro that simplifies handling functions returning absl::Status
or absl::StausOr<T>
.namespace mbo::strings
DropIndent
: Converts a raw-string text block as if it had no indent.DropIndentAndSplit
: Variant of DropIndent
that returns the result as lines.ParseString
: Parses strings respecting C++ and custom escapes as well as quotes (all configurable).ParseStringList
: Parses and splits strings respecting C++ and custom escapes as well as quotes (all configurable).StripCommentsArgs
: Arguments for StripComments
and StripLineComments
.StripComments
: Strips comments from lines.StripLineComments
: Strips comments from a single line.StripParsedCommentsArgs
: Arguments for StripParsedComments
and StripParsedLineComments
.StripParsedComments
: Strips comments from parsed lines.StripLineParsedComments
: Strips comments from a single parsed line.namespace mbo::testing
CapacityIs
which checks the capacity of a container.WhenTransformedBy
which allows to compare containers after transforming them. This sometimes allows for much more concise comparisons where a golden expectation is already available that only differs in a simple transformation.IsOk
: Tests whether an absl::Status
or absl::StatusOr
is absl::OkStatus
.IsOkAndHolds
: Tests an absl::StatusOr
for absl::OkStatus
and contents.StatusIs
: Tests an absl::Status
or absl::StatusOr
against a specific status code and message.StatusHasPayload
: Tests whether an absl::Status
or absl::StatusOr
payload map has any payload, a specific payload url, or a payload url with specific content.StatusPayloads
Tests whether an absl::Status
or absl::StatusOr
payload map matches.MBO_ASSERT_OK_AND_ASSIGN
: Simplifies testing with functions that return absl::StatusOr<T>
.MBO_ASSERT_OK_AND_MOVE_TO
: Simplifies testing with functions that return absl::StatusOr<T>
where the result requires commas, in particular structured bindings.namespace mbo::types
Cases
: Allows to switch types based on conditions.CaseIndex
: Evaluates the first non zero case (1-based, 0 if all zero).IfThen
: Helper type to generate if-then Cases
types.IfElse
: Helper type to generate else Cases
which are always true and must go last.IfFalseThenVoid
: Helper type that can be used to skip a case.IfTrueThenVoid
: Helper type to inject default cases and to ensure the required type expansion is always possible.mbo::types::CompareLess
which is compatible to std::Less but allows container optimizations.Extend
: Enables extending of struct/class types with basic functionality.ExtendNoDefault
Like Extend
but without default extender functionality.ExtendNoPrint
Like Extend
but without Printable
and Streamable
extender functionality.namespace extender
AbslStringify
: Extender that injects functionality to make an Extend
ed type work with abseil format/print functions. See Stringify
for various API extension points.AbslHashable
: Extender that injects functionality to make an Extend
ed type work with abseil hashing (and also std::hash
).Comparable
: Extender that injects functionality to make an Extend
ed type comparable. All comparators will be injected: <=>
, ==
, !=
, <
, <=
, >
, >=
.Printable
:
Extend
ed type get a std::string ToString() const
function which can be used to convert a type into a std::string
.{ 25, 42 }
.{ .first = 25, .second = 42 }
.Streamable
: Extender that injects functionality to make an Extend
ed type streamable. This allows the type to be used directly with std::ostream
s.NoDestruct<T>
: Implements a type that allows to use any type as a static constant.RefWrap<T>
: similar to std::reference_wrapper
but supports operators ->
and *
.BinarySearch
implements templated binary search algorithm.LinearSearch
implements templated linear search algorithm.ReverseSearch
implements templated reverse linear search algorithm.MaxSearch
implements templated linear search for last match algorithm.Stringify
a utility to convert structs into strings.StringifyWithFieldNames
a format control adapter for Stringify
.StringifyOptions
which can be used to control Stringify
formatting.MboTypesStringifySupport
which enables Stringify
support even if not otherwise enabled (disables Abseil stringify support in Stringify
).MboTypesStringifyDisable
which disables Stringify
support. This allows to preventStringify
MboTypesStringifyDoNotPrintFieldNames
which if present disables field names in Stringify
.MboTypesStringifyFieldNames
which adds field names to Stringify
.MboTypesStringifyOptions
which adds full format control to Stringify
.std::ostream& operator<<(std::ostream&, const MboTypesStringifySupport auto& v)
- conditioanl automatic ostream support for structs using Stringify
.ContainerConstIteratorValueType
returned the value-type of the const_iterator of a container.ContainerIsForwardIteratable
determines whether a types can be used in forward iteration.ContainerHasEmplace
determines whether a container has emplace
.ContainerHasEmplaceBack
determines whether a container has emplace_back
.ContainerHasInsert
determines whether a container has insert
.ContainerHasPushBack
determines whether a container has push_back
.ContainerHasForwardIterator
determines whether a container has begin
, end
and std::forward_iterator
compliant iterators.ContainerHasInputIterator
determines whether a container has begin
, end
and std::input_iterator
compliant iterators.GetDifferenceType
is either set to the type's difference_type
or std::ptrdiff_t
.HasDifferenceType
determines whether a type has a difference_type
.IsAggregate
determines whether a type is an aggregate.IsCharArray
determines whether a type is a char*
or char[]
related type.IsDecomposable
determines whether a type can be used in static-bindings.IsInitializerList
determines whether a type is `std::initializer type.IsBracesConstructibleV
determines whether a type can be constructe from given argument types.IsOptional
determines whether a type is a std::optional
.IsPair
determines whether a type is a std::pair
.IsSameAsAnyOfRaw
/ NotSameAsAnyOfRaw
which determine whether type is one of a list of types.IsSmartPtr
determines whether a type is a std::shared_ptr
, std::unique_ptr
or std::weak_ptr
.
IsSmartPtrImpl
.IsTuple
determines whether a type is a std::tuple
.IsVariant
determines whether a type is a std::variant
type.tstring
: Implements type tstring
a compile time string-literal type.operator"" _ts
: String literal support for Clang, GCC and derived compilers.mbo::types::TupleCat
which concatenates tuple types.In addition some Bazel macros are implemented that are not direct part of the library:
http_archive
: Simple wrapper that tests whether the archive was already loaded.github_archive
: Specialized archive wrapper that supports github that supports tagged
releases or commits.This repository requires a C++20 compiler (in case of MacOS XCode 15 is needed).
This is done so that newer features like std::source_location
can be used.
The project only comes with a Bazel BUILD.bazel file and can be added to other Bazel projects. Checkout Releases or use head ref as follows:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_helly25_proto",
url = "https://github.com/helly25/mbo/archive/refs/heads/main.tar.gz",
# See https://github.com/helly25/mbo/releases for releases.
)
The project is formatted with specific clang-format settings which require clang 16+ (in case of MacOs LLVM 16+ can be installed using brew).
Presented at C++ On Sea 2024, this presentation covers the theory behind:
mbo::hash::simple::GetHash
,mbo::container::LimitedVector
,mbo::container::LimitedMap
, andmbo::container::LimitedSet
.