Convert Figma logo to code with AI

abseil logoabseil-cpp

Abseil Common Libraries (C++)

14,876
2,597
14,876
179

Top Related Projects

GoogleTest - Google Testing and Mocking Framework

A microbenchmark support library

7,099

Super-project for modularized Boost

20,408

A modern formatting library

28,292

An open-source C++ library developed and used at Facebook.

6,172

Guidelines Support Library

Quick Overview

Abseil is an open-source collection of C++ library code designed to augment the C++ standard library. It is developed and used by Google and provides a set of common libraries that are consistent across various platforms and compilers. Abseil aims to be both efficient and compatible with future C++ standards.

Pros

  • Provides a wide range of utility functions and data structures not available in the standard library
  • Designed for performance and efficiency, with optimizations for modern hardware
  • Regularly updated and maintained by Google, ensuring compatibility with new C++ standards
  • Cross-platform support and consistent behavior across different compilers

Cons

  • Learning curve for developers not familiar with Google's coding style and conventions
  • Some features may overlap with existing standard library functionality, potentially causing confusion
  • Dependency management can be complex in larger projects
  • Not all features are available on all platforms, which may limit portability in some cases

Code Examples

  1. Using absl::StrCat for efficient string concatenation:
#include "absl/strings/str_cat.h"

std::string result = absl::StrCat("Hello, ", name, "! You are ", age, " years old.");
  1. Using absl::flat_hash_map for a high-performance hash table:
#include "absl/container/flat_hash_map.h"

absl::flat_hash_map<std::string, int> scores;
scores["Alice"] = 95;
scores["Bob"] = 87;
  1. Using absl::Time for time-related operations:
#include "absl/time/time.h"

absl::Time now = absl::Now();
absl::Duration duration = absl::Hours(2) + absl::Minutes(30);
absl::Time later = now + duration;

Getting Started

To use Abseil in your project, follow these steps:

  1. Clone the Abseil repository:

    git clone https://github.com/abseil/abseil-cpp.git
    
  2. Add Abseil to your CMakeLists.txt:

    add_subdirectory(abseil-cpp)
    target_link_libraries(your_target absl::strings absl::time absl::container)
    
  3. Include Abseil headers in your code:

    #include "absl/strings/str_cat.h"
    #include "absl/time/time.h"
    #include "absl/container/flat_hash_map.h"
    
  4. Compile your project with C++11 or later:

    g++ -std=c++11 your_file.cpp -I/path/to/abseil-cpp
    

Competitor Comparisons

GoogleTest - Google Testing and Mocking Framework

Pros of googletest

  • Focused specifically on unit testing, providing a comprehensive testing framework
  • Extensive documentation and wide community adoption
  • Supports a variety of testing styles, including value-parameterized and type-parameterized tests

Cons of googletest

  • Limited to testing functionality, unlike Abseil's broader utility library scope
  • May require more setup and configuration for complex test scenarios
  • Less integration with modern C++ features compared to Abseil

Code Comparison

googletest:

TEST(FactorialTest, HandlesZeroInput) {
  EXPECT_EQ(Factorial(0), 1);
}

Abseil:

absl::Status DoSomething(absl::string_view input) {
  if (input.empty()) {
    return absl::InvalidArgumentError("Input cannot be empty");
  }
  // ...
}

Summary

While googletest excels in providing a robust testing framework for C++ projects, Abseil offers a broader set of utilities for modern C++ development. googletest is ideal for projects focusing on comprehensive unit testing, whereas Abseil is better suited for projects seeking to enhance their overall C++ codebase with modern language features and utilities.

A microbenchmark support library

Pros of Benchmark

  • Focused specifically on microbenchmarking, providing a comprehensive suite of tools for performance testing
  • Offers more advanced features for benchmarking, such as templated benchmarks and custom counters
  • Easier to set up and use for quick performance measurements

Cons of Benchmark

  • Limited scope compared to Abseil-cpp, which offers a broader range of utilities
  • Less integration with other Google libraries and tools
  • May require additional dependencies for certain features

Code Comparison

Abseil-cpp example:

#include "absl/strings/str_cat.h"
std::string result = absl::StrCat("Hello, ", name, "!");

Benchmark example:

#include <benchmark/benchmark.h>
static void BM_StringCreation(benchmark::State& state) {
  for (auto _ : state)
    std::string empty_string;
}
BENCHMARK(BM_StringCreation);

While Abseil-cpp provides a wide range of utilities for C++ development, Benchmark focuses specifically on performance testing. Abseil-cpp offers more general-purpose tools, while Benchmark excels in creating and running microbenchmarks for code optimization.

7,099

Super-project for modularized Boost

Pros of Boost

  • Extensive library collection covering a wide range of functionalities
  • Long-standing reputation and widespread adoption in the C++ community
  • Cross-platform support and compatibility with various compilers

Cons of Boost

  • Large library size and potential overhead for projects not using all features
  • Steeper learning curve due to its extensive API and documentation
  • Longer compilation times compared to more lightweight alternatives

Code Comparison

Boost example (smart pointers):

#include <boost/shared_ptr.hpp>

boost::shared_ptr<int> ptr(new int(10));

Abseil example (smart pointers):

#include "absl/memory/memory.h"

std::unique_ptr<int> ptr = absl::make_unique<int>(10);

Summary

Boost offers a comprehensive set of libraries with a long history in the C++ ecosystem, while Abseil provides a more focused, modern approach to C++ utilities. Boost's extensive feature set comes at the cost of increased complexity and potential overhead, whereas Abseil aims for simplicity and performance. The choice between the two depends on project requirements, existing codebase compatibility, and developer preferences.

20,408

A modern formatting library

Pros of fmt

  • Lightweight and focused solely on formatting, making it easier to integrate
  • Faster compilation times due to its smaller codebase
  • More intuitive syntax for string formatting operations

Cons of fmt

  • Limited scope compared to Abseil's broader utility offerings
  • Less comprehensive documentation and community support
  • May require additional dependencies for certain advanced features

Code Comparison

fmt:

#include <fmt/core.h>
std::string result = fmt::format("Hello, {}!", name);

Abseil:

#include "absl/strings/str_format.h"
std::string result = absl::StrFormat("Hello, %s!", name);

Both libraries provide similar functionality for string formatting, but fmt offers a more modern, type-safe approach with its {} placeholders, while Abseil follows a printf-style format.

fmt is an excellent choice for projects primarily focused on string formatting and output, offering a clean and efficient solution. Abseil, on the other hand, provides a broader set of utilities and may be more suitable for larger projects requiring a comprehensive set of C++ extensions.

28,292

An open-source C++ library developed and used at Facebook.

Pros of Folly

  • More extensive feature set, including advanced concurrency primitives and networking utilities
  • Highly optimized for performance, especially in multi-threaded environments
  • Active development with frequent updates and contributions from Facebook's engineering team

Cons of Folly

  • Larger codebase and more complex API, potentially steeper learning curve
  • Heavier dependencies, which may increase build times and binary sizes
  • Some components are tightly coupled with Facebook's infrastructure, potentially limiting portability

Code Comparison

Folly's FutureExecutor:

folly::Future<int> future = folly::via(executor, [] {
  return computeExpensiveResult();
});

Abseil's absl::Notification:

absl::Notification done;
std::thread t([&done] {
  ComputeExpensiveResult();
  done.Notify();
});

Both libraries provide utilities for asynchronous programming, but Folly offers a more comprehensive set of tools with its Future abstraction, while Abseil focuses on simpler synchronization primitives.

Folly is generally more feature-rich and performance-oriented, suitable for large-scale applications with complex concurrency needs. Abseil, on the other hand, offers a more streamlined and portable set of utilities, making it easier to integrate into existing projects without significant overhead.

6,172

Guidelines Support Library

Pros of GSL

  • Lightweight and header-only library, making it easy to integrate into projects
  • Focuses specifically on core C++ Guidelines support, providing a more targeted set of utilities
  • Actively maintained by Microsoft, with regular updates and community support

Cons of GSL

  • Smaller scope compared to Abseil, offering fewer general-purpose utilities
  • Less comprehensive documentation and examples than Abseil
  • May require more manual implementation of certain features that Abseil provides out-of-the-box

Code Comparison

GSL:

#include <gsl/gsl>

void example(gsl::span<int> data) {
    for (int& item : data) {
        // Process item
    }
}

Abseil:

#include "absl/container/inlined_vector.h"

absl::InlinedVector<int, 4> example() {
    return {1, 2, 3, 4};
}

GSL focuses on providing core Guidelines Support Library features, while Abseil offers a broader range of utilities and containers. GSL's span is similar to Abseil's Span, but Abseil provides additional containers like InlinedVector. Both libraries aim to enhance C++ development, with GSL being more focused on guidelines adherence and Abseil offering a wider array of general-purpose tools.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Abseil - C++ Common Libraries

The repository contains the Abseil C++ library code. Abseil is an open-source collection of C++ code (compliant to C++14) designed to augment the C++ standard library.

Table of Contents

About Abseil

Abseil is an open-source collection of C++ library code designed to augment the C++ standard library. The Abseil library code is collected from Google's own C++ code base, has been extensively tested and used in production, and is the same code we depend on in our daily coding lives.

In some cases, Abseil provides pieces missing from the C++ standard; in others, Abseil provides alternatives to the standard for special needs we've found through usage in the Google code base. We denote those cases clearly within the library code we provide you.

Abseil is not meant to be a competitor to the standard library; we've just found that many of these utilities serve a purpose within our code base, and we now want to provide those resources to the C++ community as a whole.

Quickstart

If you want to just get started, make sure you at least run through the Abseil Quickstart. The Quickstart contains information about setting up your development environment, downloading the Abseil code, running tests, and getting a simple binary working.

Building Abseil

Bazel and CMake are the official build systems for Abseil. See the quickstart for more information on building Abseil using the Bazel build system. If you require CMake support, please check the CMake build instructions and CMake Quickstart.

Support

Abseil follows Google's Foundational C++ Support Policy. See this table for a list of currently supported versions compilers, platforms, and build tools.

Codemap

Abseil contains the following C++ library components:

  • base
    The base library contains initialization code and other code which all other Abseil code depends on. Code within base may not depend on any other code (other than the C++ standard library).
  • algorithm
    The algorithm library contains additions to the C++ <algorithm> library and container-based versions of such algorithms.
  • cleanup
    The cleanup library contains the control-flow-construct-like type absl::Cleanup which is used for executing a callback on scope exit.
  • container
    The container library contains additional STL-style containers, including Abseil's unordered "Swiss table" containers.
  • crc The crc library contains code for computing error-detecting cyclic redundancy checks on data.
  • debugging
    The debugging library contains code useful for enabling leak checks, and stacktrace and symbolization utilities.
  • flags
    The flags library contains code for handling command line flags for libraries and binaries built with Abseil.
  • hash
    The hash library contains the hashing framework and default hash functor implementations for hashable types in Abseil.
  • log
    The log library contains LOG and CHECK macros and facilities for writing logged messages out to disk, stderr, or user-extensible destinations.
  • memory
    The memory library contains memory management facilities that augment C++'s <memory> library.
  • meta
    The meta library contains compatible versions of type checks available within C++14 and C++17 versions of the C++ <type_traits> library.
  • numeric
    The numeric library contains 128-bit integer types as well as implementations of C++20's bitwise math functions.
  • profiling
    The profiling library contains utility code for profiling C++ entities. It is currently a private dependency of other Abseil libraries.
  • random
    The random library contains functions for generating psuedorandom values.
  • status
    The status library contains abstractions for error handling, specifically absl::Status and absl::StatusOr<T>.
  • strings
    The strings library contains a variety of strings routines and utilities, including a C++14-compatible version of the C++17 std::string_view type.
  • synchronization
    The synchronization library contains concurrency primitives (Abseil's absl::Mutex class, an alternative to std::mutex) and a variety of synchronization abstractions.
  • time
    The time library contains abstractions for computing with absolute points in time, durations of time, and formatting and parsing time within time zones.
  • types
    The types library contains non-container utility types, like a C++14-compatible version of the C++17 std::optional type.
  • utility
    The utility library contains utility and helper code.

Releases

Abseil recommends users "live-at-head" (update to the latest commit from the master branch as often as possible). However, we realize this philosophy doesn't work for every project, so we also provide Long Term Support Releases to which we backport fixes for severe bugs. See our release management document for more details.

License

The Abseil C++ library is licensed under the terms of the Apache license. See LICENSE for more information.

Links

For more information about Abseil: