WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Casting.hpp File Reference
#include "wpi/util/Compiler.hpp"
#include "wpi/util/type_traits.hpp"
#include <cassert>
#include <memory>
#include <optional>
#include <type_traits>

Go to the source code of this file.

Classes

struct  wpi::util::simplify_type< From >
 Define a template that can be specialized by smart pointers to reflect the fact that they are automatically dereferenced, and are not involved with the template selection process... the default implementation is a noop. More...
struct  wpi::util::simplify_type< const From >
struct  wpi::util::isa_impl< To, From, Enabler >
struct  wpi::util::isa_impl< To, From, std::enable_if_t< std::is_base_of_v< To, From > > >
struct  wpi::util::isa_impl_cl< To, From >
struct  wpi::util::isa_impl_cl< To, const From >
struct  wpi::util::isa_impl_cl< To, const std::unique_ptr< From > >
struct  wpi::util::isa_impl_cl< To, From * >
struct  wpi::util::isa_impl_cl< To, From *const >
struct  wpi::util::isa_impl_cl< To, const From * >
struct  wpi::util::isa_impl_cl< To, const From *const >
struct  wpi::util::isa_impl_wrap< To, From, SimpleFrom >
struct  wpi::util::isa_impl_wrap< To, FromTy, FromTy >
struct  wpi::util::cast_retty_impl< To, From >
struct  wpi::util::cast_retty_impl< To, const From >
struct  wpi::util::cast_retty_impl< To, From * >
struct  wpi::util::cast_retty_impl< To, const From * >
struct  wpi::util::cast_retty_impl< To, const From *const >
struct  wpi::util::cast_retty_impl< To, std::unique_ptr< From > >
struct  wpi::util::cast_retty_wrap< To, From, SimpleFrom >
struct  wpi::util::cast_retty_wrap< To, FromTy, FromTy >
struct  wpi::util::cast_retty< To, From >
struct  wpi::util::cast_convert_val< To, From, SimpleFrom >
struct  wpi::util::cast_convert_val< To, FromTy, FromTy >
struct  wpi::util::cast_convert_val< To, FromTy *, FromTy * >
struct  wpi::util::is_simple_type< X >
struct  wpi::util::CastIsPossible< To, From, Enable >
 This struct provides a way to check if a given cast is possible. More...
struct  wpi::util::CastIsPossible< To, std::optional< From > >
struct  wpi::util::CastIsPossible< To, From, std::enable_if_t< std::is_base_of_v< To, From > > >
 Upcasting (from derived to base) and casting from a type to itself should always be possible. More...
struct  wpi::util::NullableValueCastFailed< To >
 All of these cast traits are meant to be implementations for useful casts that users may want to use that are outside the standard behavior. More...
struct  wpi::util::DefaultDoCastIfPossible< To, From, Derived >
 This cast trait just provides the default implementation of doCastIfPossible to make CastInfo specializations more declarative. More...
struct  wpi::util::ValueFromPointerCast< To, From, Derived >
 This cast trait provides casting for the specific case of casting to a value-typed object from a pointer-typed object. More...
struct  wpi::util::UniquePtrCast< To, From, Derived >
 This cast trait provides std::unique_ptr casting. More...
struct  wpi::util::OptionalValueCast< To, From, Derived >
 This cast trait provides std::optional<T> casting. More...
struct  wpi::util::ConstStrippingForwardingCast< To, From, ForwardTo >
 Provides a cast trait that strips const from types to make it easier to implement a const-version of a non-const cast. More...
struct  wpi::util::ForwardToPointerCast< To, From, ForwardTo >
 Provides a cast trait that uses a defined pointer to pointer cast as a base for reference-to-reference casts. More...
struct  wpi::util::CastInfo< To, From, Enable >
 This struct provides a method for customizing the way a cast is performed. More...
struct  wpi::util::CastInfo< To, From, std::enable_if_t<!is_simple_type< From >::value > >
 This struct provides an overload for CastInfo where From has simplify_type defined. More...
struct  wpi::util::CastInfo< To, std::unique_ptr< From > >
 Provide a CastInfo specialized for std::unique_ptr. More...
struct  wpi::util::CastInfo< To, std::optional< From > >
 Provide a CastInfo specialized for std::optional<From>. More...
struct  wpi::util::ValueIsPresent< T, Enable >
 ValueIsPresent provides a way to check if a value is, well, present. More...
struct  wpi::util::ValueIsPresent< std::optional< T > >
struct  wpi::util::ValueIsPresent< T, std::enable_if_t< IsNullable< T > > >
struct  wpi::util::detail::IsaCheckPredicate< Types >
struct  wpi::util::detail::IsaAndPresentCheckPredicate< Types >

Namespaces

namespace  wpi
namespace  wpi::util
namespace  wpi::util::detail
 These are wrappers over isa* function that allow them to be used in generic algorithms such as wpi::util:all_of, wpi::util::none_of, etc.

Typedefs

template<typename OptionalDerived, typename Default>
using wpi::util::detail::SelfType
 A helper to derive the type to use with Self for cast traits, when the provided CRTP derived type is allowed to be void.

Functions

template<typename To, typename From>
bool wpi::util::isa (const From &Val)
 isa<X> - Return true if the parameter to the template is an instance of one of the template type arguments.
template<typename First, typename Second, typename... Rest, typename From>
bool wpi::util::isa (const From &Val)
template<typename To, typename From>
decltype(auto) wpi::util::cast (const From &Val)
 cast<X> - Return the argument parameter cast to the specified type.
template<typename To, typename From>
decltype(auto) wpi::util::cast (From &Val)
template<typename To, typename From>
decltype(auto) wpi::util::cast (From *Val)
template<typename To, typename From>
decltype(auto) wpi::util::cast (std::unique_ptr< From > &&Val)
template<typename T>
bool wpi::util::detail::isPresent (const T &t)
template<typename T>
decltype(auto) wpi::util::detail::unwrapValue (T &t)
template<typename To, typename From>
decltype(auto) wpi::util::dyn_cast (const From &Val)
 dyn_cast<X> - Return the argument parameter cast to the specified type.
template<typename To, typename From>
decltype(auto) wpi::util::dyn_cast (From &Val)
template<typename To, typename From>
decltype(auto) wpi::util::dyn_cast (From *Val)
template<typename To, typename From>
decltype(auto) wpi::util::dyn_cast (std::unique_ptr< From > &Val)
template<typename... X, class Y>
bool wpi::util::isa_and_present (const Y &Val)
 isa_and_present<X> - Functionally identical to isa, except that a null value is accepted.
template<typename... X, class Y>
bool wpi::util::isa_and_nonnull (const Y &Val)
template<class X, class Y>
auto wpi::util::cast_if_present (const Y &Val)
 cast_if_present<X> - Functionally identical to cast, except that a null value is accepted.
template<class X, class Y>
auto wpi::util::cast_if_present (Y &Val)
template<class X, class Y>
auto wpi::util::cast_if_present (Y *Val)
template<class X, class Y>
auto wpi::util::cast_if_present (std::unique_ptr< Y > &&Val)
template<class X, class Y>
auto wpi::util::cast_or_null (const Y &Val)
template<class X, class Y>
auto wpi::util::cast_or_null (Y &Val)
template<class X, class Y>
auto wpi::util::cast_or_null (Y *Val)
template<class X, class Y>
auto wpi::util::cast_or_null (std::unique_ptr< Y > &&Val)
template<class X, class Y>
auto wpi::util::dyn_cast_if_present (const Y &Val)
 dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case of optionals) value is accepted.
template<class X, class Y>
auto wpi::util::dyn_cast_if_present (Y &Val)
template<class X, class Y>
auto wpi::util::dyn_cast_if_present (Y *Val)
template<class X, class Y>
auto wpi::util::dyn_cast_or_null (const Y &Val)
template<class X, class Y>
auto wpi::util::dyn_cast_or_null (Y &Val)
template<class X, class Y>
auto wpi::util::dyn_cast_or_null (Y *Val)
template<class X, class Y>
CastInfo< X, std::unique_ptr< Y > >::CastResultType wpi::util::unique_dyn_cast (std::unique_ptr< Y > &Val)
 unique_dyn_cast<X> - Given a unique_ptr<Y>, try to return a unique_ptr<X>, taking ownership of the input pointer iff isa<X>(Val) is true.
template<class X, class Y>
auto wpi::util::unique_dyn_cast (std::unique_ptr< Y > &&Val)
template<class X, class Y>
CastInfo< X, std::unique_ptr< Y > >::CastResultType wpi::util::unique_dyn_cast_or_null (std::unique_ptr< Y > &Val)
template<class X, class Y>
auto wpi::util::unique_dyn_cast_or_null (std::unique_ptr< Y > &&Val)

Variables

template<typename T>
constexpr bool wpi::util::IsNullable
template<typename... Types>
constexpr detail::IsaCheckPredicate< Types... > wpi::util::IsaPred {}
 Function object wrapper for the wpi::util::isa type check.
template<typename... Types>
constexpr detail::IsaAndPresentCheckPredicate< Types... > wpi::util::IsaAndPresentPred {}
 Function object wrapper for the wpi::util::isa_and_present type check.