ext::format_string_and_location

Synopsis

Declared in <folly/result/rich_msg.h>

template<typename... Args>
class format_string_and_location;

Description

Rich error users probably want rich_msg instead, see below. This is meant to enable library authors to make concise APIs, in the style epitaph or ...coded_rich_error.

Captures a source location together with a literal string ‐‐ either for fmt formatting with arguments, or one without substitutions. Usage: template <typename... As> void yourFn(format_string_and_location<std::type_identity_t<As>...> = "")

The type_identity allows implicit construction of this type from string literals (its sole ctor is consteval). Adding that nested template makes the argument non‐deducible. Without that, template deduction would attempt to deduce const char [N] ‐> format_string_and_location, which would fail since template deduction does not consider implicit conversions.

BUG ALERT: Due to https://github.com/llvm/llvm‐project/issues/137907 avoid writing constructors like this: T(source_location sl = source_location::current()) A constructor with a defaulted source_location should take at least one mandatory argument to avoid this pitfall.

Member Functions

Name

Description

format_string_and_location [constructor]

Constructs from a string literal, capturing the call‐site location.

as_exception_shared_string

as_exception_shared_string overloads

location

Returns the captured source location.

Friends

Name

Description

folly::rich_msg

A message that can automatically capture source locations.

Created with MrDocs