WPILibC++ 2024.3.2
FunctionExtras.h File Reference

This file provides a collection of function (or more generally, callable) type erasure utilities supplementing those provided by the standard library in <function>. More...

#include "wpi/PointerIntPair.h"
#include "wpi/PointerUnion.h"
#include "wpi/STLForwardCompat.h"
#include "wpi/MemAlloc.h"
#include "wpi/type_traits.h"
#include <cstddef>
#include <cstring>
#include <memory>
#include <type_traits>

Go to the source code of this file.

Classes

class  wpi::detail::UniqueFunctionBase< ReturnT, ParamTs >
 
struct  wpi::detail::UniqueFunctionBase< ReturnT, ParamTs >::IsSizeLessThanThresholdT< T, class >
 
struct  wpi::detail::UniqueFunctionBase< ReturnT, ParamTs >::CallbacksHolder< CallableT, CalledAs, Enable >
 
struct  wpi::detail::UniqueFunctionBase< ReturnT, ParamTs >::CallbacksHolder< CallableT, CalledAs, EnableIfTrivial< CallableT > >
 
struct  wpi::detail::UniqueFunctionBase< ReturnT, ParamTs >::CalledAs< T >
 
class  wpi::unique_function< R(P...)>
 
class  wpi::unique_function< R(P...) const >
 

Namespaces

namespace  wpi
 
namespace  wpi::detail
 

Typedefs

template<typename T >
using wpi::detail::EnableIfTrivial = std::enable_if_t< std::is_trivially_move_constructible< T >::value &&std::is_trivially_destructible< T >::value >
 
template<typename CallableT , typename ThisT >
using wpi::detail::EnableUnlessSameType = std::enable_if_t<!std::is_same< remove_cvref_t< CallableT >, ThisT >::value >
 
template<typename CallableT , typename Ret , typename... Params>
using wpi::detail::EnableIfCallable = std::enable_if_t< std::disjunction< std::is_void< Ret >, std::is_same< decltype(std::declval< CallableT >()(std::declval< Params >()...)), Ret >, std::is_same< const decltype(std::declval< CallableT >()(std::declval< Params >()...)), Ret >, std::is_convertible< decltype(std::declval< CallableT >()(std::declval< Params >()...)), Ret > >::value >
 

Detailed Description

This file provides a collection of function (or more generally, callable) type erasure utilities supplementing those provided by the standard library in <function>.

It provides unique_function, which works like std::function but supports move-only callable objects and const-qualification.

Future plans:

  • Add a function that provides ref-qualified support, which doesn't work with std::function.
  • Provide support for specifying multiple signatures to type erase callable objects with an overload set, such as those produced by generic lambdas.
  • Expand to include a copyable utility that directly replaces std::function but brings the above improvements.

Note that LLVM's utilities are greatly simplified by not supporting allocators.

If the standard library ever begins to provide comparable facilities we can consider switching to those.