Skip to content

Commit

Permalink
third_party/fuchsia: Copybara import of the fit library
Browse files Browse the repository at this point in the history
  - 59a3b03935223d21a186a59e0fe1fbc53e46aef3 [fit] Reduce unnecessary function instantiations
  - 9b9b190756c0bf3c40671bf576cc90fe4b50fc21 [fit] Rename fit::function template parameter
  - f73d8db89708db77a465d7757777cf1c64899d3f [fit] Fix null_target::ops duplicate symbol errors

GitOrigin-RevId: 59a3b03935223d21a186a59e0fe1fbc53e46aef3
Change-Id: Idb97ec03e5ff3b0b8b7238af536f9c63851cabcb
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/109718
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Rob Mohr <[email protected]>
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Commit-Queue: Wyatt Hepler <[email protected]>
  • Loading branch information
Fuchsia Authors authored and CQ Bot Account committed Sep 9, 2022
1 parent 63a2ee5 commit 5d0e0ab
Show file tree
Hide file tree
Showing 3 changed files with 1,228 additions and 170 deletions.
72 changes: 36 additions & 36 deletions third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace fit {

template <size_t inline_target_size, bool require_inline, typename Callable>
template <size_t inline_target_size, bool require_inline, typename FunctionType>
class function_impl {
static_assert(std::is_function<Callable>::value,
static_assert(std::is_function<FunctionType>::value,
"fit::function must be instantiated with a function type, such as void() or "
"int(char*, bool)");
};

template <size_t inline_target_size, bool require_inline, typename Callable>
template <size_t inline_target_size, bool require_inline, typename FunctionType>
class callback_impl {
static_assert(std::is_function<Callable>::value,
static_assert(std::is_function<FunctionType>::value,
"fit::callback must be instantiated with a function type, such as void() or "
"int(char*, bool)");
};
Expand Down Expand Up @@ -235,15 +235,15 @@ class function_impl<inline_target_size, require_inline, Result(Args...)> final

// Creates a function with a target moved from another function,
// leaving the other function with an empty target.
function_impl(function_impl&& other) : base(static_cast<base&&>(other)) {}
function_impl(function_impl&& other) noexcept : base(static_cast<base&&>(other)) {}

// Destroys the function, releasing its target.
~function_impl() = default;

// Assigns the function to an empty target. Attempting to invoke the
// function will abort the program.
function_impl& operator=(decltype(nullptr)) {
base::assign(nullptr);
base::assign_null();
return *this;
}

Expand All @@ -263,7 +263,7 @@ class function_impl<inline_target_size, require_inline, Result(Args...)> final
result_type>,
not_self_type<Callable>>
operator=(Callable&& function_target) {
base::assign(std::forward<Callable>(function_target));
base::assign_callable(std::forward<Callable>(function_target));
return *this;
}

Expand All @@ -279,10 +279,10 @@ class function_impl<inline_target_size, require_inline, Result(Args...)> final
delete;

// Move assignment
function_impl& operator=(function_impl&& other) {
function_impl& operator=(function_impl&& other) noexcept {
if (&other == this)
return *this;
base::assign(static_cast<base&&>(other));
base::assign_function(static_cast<base&&>(other));
return *this;
}

Expand Down Expand Up @@ -313,30 +313,30 @@ class function_impl<inline_target_size, require_inline, Result(Args...)> final
}
};

template <size_t inline_target_size, bool require_inline, typename Callable>
void swap(function_impl<inline_target_size, require_inline, Callable>& a,
function_impl<inline_target_size, require_inline, Callable>& b) {
template <size_t inline_target_size, bool require_inline, typename FunctionType>
void swap(function_impl<inline_target_size, require_inline, FunctionType>& a,
function_impl<inline_target_size, require_inline, FunctionType>& b) {
a.swap(b);
}

template <size_t inline_target_size, bool require_inline, typename Callable>
bool operator==(const function_impl<inline_target_size, require_inline, Callable>& f,
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator==(const function_impl<inline_target_size, require_inline, FunctionType>& f,
decltype(nullptr)) {
return !f;
}
template <size_t inline_target_size, bool require_inline, typename Callable>
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator==(decltype(nullptr),
const function_impl<inline_target_size, require_inline, Callable>& f) {
const function_impl<inline_target_size, require_inline, FunctionType>& f) {
return !f;
}
template <size_t inline_target_size, bool require_inline, typename Callable>
bool operator!=(const function_impl<inline_target_size, require_inline, Callable>& f,
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator!=(const function_impl<inline_target_size, require_inline, FunctionType>& f,
decltype(nullptr)) {
return !!f;
}
template <size_t inline_target_size, bool require_inline, typename Callable>
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator!=(decltype(nullptr),
const function_impl<inline_target_size, require_inline, Callable>& f) {
const function_impl<inline_target_size, require_inline, FunctionType>& f) {
return !!f;
}

Expand Down Expand Up @@ -393,15 +393,15 @@ class callback_impl<inline_target_size, require_inline, Result(Args...)> final

// Creates a callback with a target moved from another callback,
// leaving the other callback with an empty target.
callback_impl(callback_impl&& other) : base(static_cast<base&&>(other)) {}
callback_impl(callback_impl&& other) noexcept : base(static_cast<base&&>(other)) {}

// Destroys the callback, releasing its target.
~callback_impl() = default;

// Assigns the callback to an empty target. Attempting to invoke the
// callback will abort the program.
callback_impl& operator=(decltype(nullptr)) {
base::assign(nullptr);
base::assign_null();
return *this;
}

Expand All @@ -418,15 +418,15 @@ class callback_impl<inline_target_size, require_inline, Result(Args...)> final
result_type>,
not_self_type<Callable>>
operator=(Callable&& callback_target) {
base::assign(std::forward<Callable>(callback_target));
base::assign_callable(std::forward<Callable>(callback_target));
return *this;
}

// Move assignment
callback_impl& operator=(callback_impl&& other) {
callback_impl& operator=(callback_impl&& other) noexcept {
if (&other == this)
return *this;
base::assign(static_cast<base&&>(other));
base::assign_function(static_cast<base&&>(other));
return *this;
}

Expand Down Expand Up @@ -469,30 +469,30 @@ class callback_impl<inline_target_size, require_inline, Result(Args...)> final
}
};

template <size_t inline_target_size, bool require_inline, typename Callable>
void swap(callback_impl<inline_target_size, require_inline, Callable>& a,
callback_impl<inline_target_size, require_inline, Callable>& b) {
template <size_t inline_target_size, bool require_inline, typename FunctionType>
void swap(callback_impl<inline_target_size, require_inline, FunctionType>& a,
callback_impl<inline_target_size, require_inline, FunctionType>& b) {
a.swap(b);
}

template <size_t inline_target_size, bool require_inline, typename Callable>
bool operator==(const callback_impl<inline_target_size, require_inline, Callable>& f,
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator==(const callback_impl<inline_target_size, require_inline, FunctionType>& f,
decltype(nullptr)) {
return !f;
}
template <size_t inline_target_size, bool require_inline, typename Callable>
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator==(decltype(nullptr),
const callback_impl<inline_target_size, require_inline, Callable>& f) {
const callback_impl<inline_target_size, require_inline, FunctionType>& f) {
return !f;
}
template <size_t inline_target_size, bool require_inline, typename Callable>
bool operator!=(const callback_impl<inline_target_size, require_inline, Callable>& f,
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator!=(const callback_impl<inline_target_size, require_inline, FunctionType>& f,
decltype(nullptr)) {
return !!f;
}
template <size_t inline_target_size, bool require_inline, typename Callable>
template <size_t inline_target_size, bool require_inline, typename FunctionType>
bool operator!=(decltype(nullptr),
const callback_impl<inline_target_size, require_inline, Callable>& f) {
const callback_impl<inline_target_size, require_inline, FunctionType>& f) {
return !!f;
}

Expand Down
Loading

0 comments on commit 5d0e0ab

Please sign in to comment.