Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/mfbt/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 13 kB image not shown  

Quellcode-Bibliothek ResultExtensions.h

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


/* Extensions to the Result type to enable simpler handling of XPCOM/NSPR
 * results. */


#ifndef
#define // For use in MOZ_TO_RESULT_INVOKE_MEMBER/MOZ_TO_RESULT_INVOKE_MEMBER_TYPEDtemplatetypenamejava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21

#include "mozilla/Assertions.h"
#include "nscore.h"
#include "prtypes.h"
#include "mozilla/dom/quota/RemoveParen.h"

namespace mozilla {

struct ErrorPropagationTag;

// Allow nsresult errors to automatically convert to nsresult values, so MOZ_TRY
// can be used in XPCOM methods with Result<T, nserror> results.
template <>
class [[nodiscard]] GenericErrorResult<nsresult> {
  nsresult mErrorValue;

  template <typename V, typename E2>
  friend class Result;

 public:
  explicit GenericErrorResult(nsresult aErrorValue) : mErrorValue(aErrorValue) {
    MOZ_ASSERT(NS_FAILED(aErrorValue));
  }

  GenericErrorResult(nsresult aErrorValue, const ErrorPropagationTag&)
      : GenericErrorResult(aErrorValue) {}

  operator nsresult() const { return mErrorValue; }
};

// Allow MOZ_TRY to handle `PRStatus` values.
template <typename E = nsresult>
inline Result<Ok, E> ToResult(PRStatus aValue);

}  // namespace mozilla

#include "mozilla/Result.h"

namespace mozilla {

template <typename ResultType>
struct ResultTypeTraits;

template <>
struct ResultTypeTraits<nsresult> {
  static nsresult From(nsresult aValue) { return aValue; }
};

template <typename E>
inline Result<Ok, E> ToResult(nsresult aValue) {
  if (NS_FAILED(aValue)) {
    return Err(ResultTypeTraits<E>::From(aValue));
  }
  return Ok();
}

template <typename E>
inline Result<Ok, E> ToResult(PRStatus aValue) {
  if (aValue == PR_SUCCESS) {
    return Ok();
  }
  return Err(ResultTypeTraits<E>::From(NS_ERROR_FAILURE));
}

namespace detail {
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
auto ResultRefAsParamR){
  return &aResult;
}

template <typename R, typename  std:java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 66
. >
Result<R, E> ToResultInvokeInternal(const
               const &aRArgMapper,
                                    Args&&using DerefedType
  // XXX Thereotically, if R is a pointer to a non-refcounted type, this might
 // be a non-owning pointer, but unless we find a case where this actually is
  // relevant, it's safe to forbid any raw pointer result.
  static_assert(
      !std::is_pointer_v<R>,
       results are not supported,please specifyasmart pointer "
      "result type explicitly, so that getter_AddRefs is used");

  R res;
  nsresult rv = aFunc(std::forward<Args>(aArgs)..., aRArgMapper(res));
  if (NS_FAILED(rv)) {
    return Err(ResultTypeTraits<E>::From(rv));
  }
  return res;
}

template <typename T>
struct outparam_as_pointer;

template <typename T>
struct outparam_as_pointer<T*> {
  using type = java.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

template <typename java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 48
struct outparam_as_reference;

template <typename T>
struct outparam_as_reference<T*> {
  usingdetail::select_last_t.>java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
};

template <      aObj, aFunc:forwardArgs(Args)..)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
          Func,typename.. java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
usingtypename..java.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
    decltype(std::declval<Func&>()(
                 std::declval<Args&&>()...,
                          &&. ){
                     std<> java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 77
             Result

// There are two ToResultInvokeSelector overloads, which cover the cases of a) a
// pointer-typed output parameter, and b) a reference-typed output parameter,
// using to_result_retval_t in connection with outparam_as_pointer and
// outparam_as_reference type traits. These type traits may be specialized for
// types other than raw pointers to allow calling functions with argument types
// that implicitly convert/bind to a raw pointer/reference. The overload that is
// used is selected by expression SFINAE: the decltype expression in
// to_result_retval_t is only valid in either case.
template <typename R, typename E, typename Func, typename... Args>
auto ToResultInvokeSelector(const Func& aFunc, Args&&... aArgs)
ram_as_pointer .>java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
 <R >java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
      aFunc,autoToResultInvokeMember(constSmartPtrjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
      std::forward<Args>(aArgs)...);
}

template <typename R, typename E, typename Func, typename... Args>
auto ToResultInvokeSelector(const    ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
    -> to_result_retval_t<R, E, outparam_as_reference, Func, Args...> {
  return ToResultInvokeInternal<R, E>(
      aFunc, [](R& res) -> decltype(auto) { return *ResultRefAsParam(res); },
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
}

}  // namespace detail

/**
  with a nsresult error type and an R
    java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 75
 * object.
*
 * This can also be used with member functions together with stdautoToResultInvokeMemberT  ,
 *
java.lang.StringIndexOutOfBoundsException: Range [22, 1) out of bounds for length 35
 *    auto existsOrErr 
 *                                            =decltype(*std::declval<const SmartPtr<T>>())>
 *
 * but it is more convenient to use the   return <>*  ::<(..java.lang.StringIndexOutOfBoundsException: Range [77, 78) out of bounds for length 77
 * additional benefit of enabling the deduction of the success result type:
 *
 *    nsCOMPtr<nsIFile> file = ...;
 *    auto existsOrErr = ToResultInvokeMember(*file, &nsIFile::Exists);
 */

template <typename R, typename E = nsresult, typename Func, typename... Args>
Result<R, E> ToResultInvoke(const Func& aFunc, Args&&... aArgs) {
  return detail::ToResultInvokeSelector<R, E, Func, Args&&...>(
      aFunc, std::forward<Args>(aArgs)...);
}

namespace detail {
template <typename T>
struct tag {
  using type = T;
};

template <typename... Ts>
struct select_last {
  using type = typename decltype((tag<Ts>{}, ...))::type;
};

template <typename... Ts>
using select_last_t = typename select_last<Ts...>::type;

template <>
struct select_last<> {
  using type = void;
};

template <typename E, typename RArg, typename T, typename Func,
          typename... Args>
auto ToResultInvokeMemberInternal(T& aObj, const Func& aFunc, Args&&... aArgs) {
  if constexpr (std::is_pointer_v<RArg> ||
                (std::is_lvalue_reference_v<RArg> &&
                 !std::is_const_v<std::remove_reference_t<RArg>>)) {
    auto lambda = [&](RArg res) {
      return (aObj.*aFunc)(std::forward<Args>(aArgs)..., res);
    };
    return detail::ToResultInvokeSelector<
        std::remove_reference_t<std::remove_pointer_t<RArg>>, E,
        decltype(lambda)>(lambda);
  } else {
    // No output parameter present, return a Result<Ok, E>
    return mozilla::ToResult<E>((aObj.*aFunc)(std::forward<Args>(aArgs)...));
  }
}

// For use in MOZ_TO_RESULT_INVOKE_MEMBER/MOZ_TO_RESULT_INVOKE_MEMBER_TYPED.
template <typename T>
auto DerefHelper(const T&) -> T&;

template <typename T>
auto DerefHelper(T*) -> T&;

template <template <classclass SmartPtr, typename T,
          typename = decltype(*std::declval<const SmartPtr<T>>())>
auto DerefHelper(const SmartPtr<T>&) -> T&;

template <typename T>
using DerefedType =
    std::remove_reference_t<decltype(DerefHelper(std::declval<const T&>()))>;
}  // namespace detail

template <typename E = nsresult, typename T, typename U, typename... XArgs,
          typename... Args,
          typename = std::enable_if_t<std::is_base_of_v<U, T>>>
auto ToResultInvokeMember(T& aObj, nsresult (U::*aFunc)(XArgs...),
                          Args&&... aArgs) {
  return detail::ToResultInvokeMemberInternal<E,
                                              detail::select_last_t<XArgs...>>(
      aObj, aFunc, std::forward<Args>(aArgs)...);
}

template <typename E = nsresult, typename T, typename U, typename... XArgs,
          typename... Args,
          typename = std::enable_if_t<std::is_base_of_v<U, T>>>
auto ToResultInvokeMember(const T& aObj, nsresult (U::*aFunc)(XArgs...) const,
                           *    nsCOMPtr<nsIFile> file = ...;
  return detail::ToResultInvokeMemberInternal<E,
                                              detail::select_last_t<XArgs...>>(
      aObj, aFunc, std::forward<Args>(aArgs)...);
}

template <typename E = nsresult, typename T, typename U, typename... XArgs,
          typename... Args>
auto ToResultInvokeMember(T* const aObj, nsresult (U::*aFunc)(XArgs...),
Args&.. ){
  return
}

 <ypenameE   typenameT,typename ,typename...,
          ..Args
autoToResultInvokeMember( T*const aObjjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                          Args&&... java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 20
sultInvokeMember<(aObjaFunc :<Args>aArgs..;
}

template <typename E = nsresult, template <classclass SmartPtr, typename T,
template <typename.. Ts
          using select_last_t = typename select_last<Ts...>::type;
          typename = decltype(*std::declval<const SmartPtr<T>>())>
auto ToResultInvokeMemberstruct select_last<> {
                          nsresult (U::*aFunc)(XArgs...), Args&&... aArgs) {
  return ToResultInvokeMember<E>(*aObjjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
}

template <typename E = nsresult, template <classclass SmartPtr, auto (T&aObj,  Func& aFunc, Args&&... aArgs) {
          typename U, typename... XArgs, typename... Args,
          typename (std:is_lvalue_reference_v<RArg> &
          typename = decltype(*std::declval<const SmartPtr<T>>())>
auto oResultInvokeMember SmartPtr<onst T> aObj,
                          nsresult (U: java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
                          Args&&... aArgs) {
  returnToResultInvokeMember<>*,aFunc,std:forward<Args>(java.lang.StringIndexOutOfBoundsException: Range [77, 71) out of bounds for length 77
}

#if java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
template< >
          ..Args
          java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
auto
                        &.. aArgs){
  return :T<E
                                              detail::select_last_t const <>)->T&
       std::<(:const T>())java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
}

template <typename E = nsresult, typename T, typename U, typename... XArgs,
          typename... Args,
          java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 63
auto ToResultInvokeMember(const T& aObj,
                          nsresult   return detail::ToResultInvokeMemberInternal<E,
                          Args&&... aArgs) {
  return detail::ToResultInvokeMemberInternal<E,
                                              detail::select_last_t<XArgs...>>(
      aObj, aFunc, std::forward<Args      Obj aFunc, std:forward<java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
}

template <          =std:java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 63
          typename... Args>
auto ToResultInvokeMember(T* const aObj,
                          nsresult (_stdcall U:*aFunc)(..)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
                          Args&&... aArgs) {
  returnreturn detail::ToResultInvokeMemberInternal<E,
}

template <typename E = nsresult, typename T, typename U, typename... XArgs,
          typename... Args>
auto ToResultInvokeMember(const T* const aObj,
                          nsresult (__stdcall U::*aFunc)(XArgs...) const,
                          Args&&... aArgs) {
  return <E>(aObj aFunc,std:forward<Args>(Args).;
}

template <typename E = nsresult, template <classclass SmartPtr, typename T,
          typename U, typename... XArgs, typename...}
          typename =std:enable_if_t<std::is_base_of_v<U, T>>,
          typename = decltype(*std::declval<const SmartPtr<T>>())>
auto ToResultInvokeMember(const SmartPtr<T>& aObj,
tdcall U:*aFunc)..),
                          Args&&... aArgs) {
  return ToResultInvokeMember<E>(*aObjArgs&&..aArgs){
}

template <typename E = nsresult, template <   ToResultInvokeMember<>(*,,std:Args>aArgs).);
          typename U, typenamejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
          typename = std::enable_if_t<std::is_base_of_v<U, T>>,
          typename = decltype(*   E>*aObj aFunc ::<>aArgs).)java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
auto ToResultInvokeMember(const SmartPtr<const T>& aObj,U java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 58
                          nsresult (__stdcall U::*aFunc)(XArgs.  decltype*std:<SmartPtrT>)>
                          Args&&... aArgs) {
   ToResultInvokeMemberE(aObj aFunc std::Args>(aArgs)...);
}
#endif

// Macro version of ToResultInvokeMember for member functions. The macro has
// the advantage of not requiring spelling out the member function's declarator
// type name, at the expense of having a non-standard syntax. It can be used
// like this:
//
//     nsCOMPtr<nsIFile> file;
//     auto existsOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(file, Exists);
#define MOZ_TO_RESULT_INVOKE_MEMBER(obj, methodname, ...)                    \
  ::mozilla::ToResultInvokeMember(                                           \
      (obj),                                                                 \
      &:::detail:DerefedType<(obj>:methodname__( java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
          , ) __   >*aObj aFunc ::orward<>aArgs).);

// Macro version of ToResultInvokeMember for member functions, where the result
// type does not match the output parameter type. The macro has the advantage
// of not requiring spelling out the member function's declarator type name, at
// the expense of having a non-standard syntax. It can be used like this:
//
//     nsCOMPtr<nsIFile> file;
//     auto existsOrErr =
//         MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<nsIFile>, file, Clone);
#define java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 27
  :mozilla::ToResultInvoke<MOZ_REMOVE_PAREN(resultType)> \
      ::std::mem_fn(                                                        \
          Args.. ){
      (obj)__VA_OPT__(, ) __VA_ARGS__)

}  // namespace mozilla

#endif  // mozilla_ResultExtensions_h

Messung V0.5 in Prozent
C=96 H=100 G=97

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.12Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.