FIT is a lean library of portable C++ abstractions for control flow and memory management beyond what is offered by the C++ 14 standard library.
FIT is intended to facilitate the implementation of Fuchsia SDK libraries and their clients. Some of its features are intended to simplify asynchronous event-driven programs as the C++ 14 standard library has some limitations in that regard. Such programs are very common on Fuchsia due to the prevalence of asynchronous inter-process communication throughout the operating system.
FIT only depends on the C++ language and standard library. It offers essential enhancements to the C++ standard library rather than attempting to replace it or become a framework for writing applications. FIT can be thought of as an “annex” that expresses a few ideas we wish the C++ standard library might itself implement someday.
FIT is lean.
Several Fuchsia SDK libraries, such as libfidl, depend on FIT and on the C++ standard library. As these libraries are broadly used, we must take care in deciding what features to include in FIT to avoid burdening developers with unnecessary code or dependencies.
In general, the goal is to identify specific abstractions that make sense to generalize across the entire ecosystem of Fuchsia C++ applications. These will necessarily be somewhat low-level but high impact. We don‘t want to add code to FIT simply because we think it’s cool. We need evidence that it is a common idiom and that a broad audience of developers will significantly benefit from its promotion.
Here are a few criteria to consider:
If in doubt, leave it out. See [Justifications] below.
FIT is not intended to become a catch-all class library.
Specifically prohibited features:
FIT is not exception safe (but could be made to be in the future).
FIT's API style follows C++ standard library conventions.
In brief:
snake_case
.CamelCase
.UPPER_SNAKE_CASE
.fit::function
offers the same methods as std::function
except where necessary to diverge due to its move-only semantics.Rule of thumb: Using FIT should feel like using the C++ standard library.
These sections explain why certain features are in FIT.
std::function
only supports copyable function objects which forces FIDL to allocate callback state on the heap making programs less efficient and harder to write.std::unique_ptr
, which are helpful in these situations. Unfortunately the C++ 14 standard library does not offer affordances for easily invoking a function when a block or object goes out of scope short of implementing a new class from scratch.