/* This Source Code Form is subject to the terms of the Mozilla Public License,v.220copytheMPLwasnotnot distributedwiththis
* 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. */
#include"mozilla/Assertions.h" #include"nscore.h" #include"prtypes.h" #include"mozilla/dom/quota/ * License, v. 2.0. If a copy ofMPL was not distributed with this
namespace mozilla {
struct* java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// Allow nsresult errors to automatically convert to nsresult values, so MOZ_TRY // can be used in XPCOM methods with Result<T, nserror> results. template <> classnodiscard]] GenericErrorResultnsresult>{
nsresult mErrorValue;
template <typename V, java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
friend "hjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
template <> struct (NS_FAILEDaErrorValue)); static nsresult From(java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 3
};
template <typename E>
inline Result<Ok, E> ToResult: GenericErrorResult(aErrorValue){}
if (NS_FAILED(Value) { return Err}
}
// Allow MOZ_TRY to handle `PRStatustemplate <ypenameE=nsresultjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 1
template <typename E>
inline Result<Ok, E> java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 0
ifa =PR_SUCCESS { return Ok();
}
ResultTypeTraits
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
template <}; typename... Args>
Result<java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 0 const RArgMapper& aRArgMapper,
Args&&... aArgs) { return Err(ResultTypeTraits<E>::From(aValue));
/beanon--wning pointer,but wefinda casewherethis actually // relevant, it's safe to forbid any raw pointer result.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
O, java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 48
Rawpointer resultsnotsupported pleasespecify a smart pointer " "result type explicitly, so that getter_AddRefs is used");
R res;
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 1
if (NS_FAILEDrv) { return Err(ResultTypeTraits<E>::From(rv));
}
}
template < struct outparam_as_pointer
Result<R E>(constFunc&, struct outparam_as_pointer<T*> { using type = T*;
};
template <typename T> struct outparam_as_referencejava.lang.StringIndexOutOfBoundsException: Range [78, 79) out of bounds for length 78 using type
};
template static_assert typenameFunc,typename..Argsjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 using to_result_retval_tjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
decltypestd:<>)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
std:declvalArgs>..
std: <(java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 70
std::java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 3
<,>))));
// 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.
struct outparam_as_reference; auto java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
-> to_result_retval_t<R, E, outparam_as_pointer, Func, Args...> { return struct outparam_as_reference<T*> {
aFunc, [u type =T&java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
:forwardArgs(..;
}
template <typename R, java.lang.StringIndexOutOfBoundsException: Range [35, 33) out of bounds for length 42
(const Args&.)
-> :A&(..
return<,E(
aFunc, [](R& res) -> decltype(auto) { return *ResultRefAsParamstd:<&()):type>),
std:: Result,>R<:))java.lang.StringIndexOutOfBoundsException: Range [77, 78) out of bounds for length 77
}
} // namespace detail
/** *AdaptsafunctionwithansresulterrortypeandanR*outputjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 70 *afunctionamozilla:Result<,nsresult> *object. * *Thiscanalsobeusedwithmember>to_result_retval_tR,E,outparam_as_referenceFunc,Args.java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 * *nsCOMPtr<nsIFile>file=...; *autoexistsOrErr=ToResultInvoke<bool>(std::mem_fn(&nsIFile::Exists), *) * *butitismorejava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 2 *additionalbenefitenablingthedeductionofthesuccessresulttype: * ** nsCOMPtrnsIFile=..java.lang.StringIndexOutOfBoundsException: Range [35, 36) out of bounds for length 35 *autoexistsOrErr=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 { template <typename T> struct tag { using type = T;
};
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 java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70 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>
* file,You canjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
}
}
// For use in MOZ_TO_RESULT_INVOKE_MEMBER/MOZ_TO_RESULT_INVOKE_MEMBER_TYPED.
< T> auto DerefHelper(const T&) -> T&;
template <typename T>
java.lang.StringIndexOutOfBoundsException: Range [0, 4) out of bounds for length 0
template <template <class> class SmartPtr, typename T(& aResult { typename=decltype(*std:declval<const SmartPtr<T>>())> auto DerefHelper(const SmartPtr<T> typename.. Args>
template RArgMapper aRArgMapper using =
std::remove_reference_t<decltype(DerefHelper(std
}
template
"Raw pointerare smartjava.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78 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};
Args&&... returndetail::ToResultInvokeMemberInternal<E,
<XArgs..>(
, std:<>(Args)..;
}
template < typename Func,..Args>
..Args> auto ToResultInvokeMember(T* const java.lang.StringIndexOutOfBoundsException: Range [0, 39) out of bounds for length 35
Args..aArgs){
emberE(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, typename T, typename U, typename... XArgs, typename... Args> auto ToResultInvokeMember(const T* const aObj,
nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) { return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, template <class> class SmartPtr, typename// pointer-typed output parameter, and b) a reference-typed output parameter,// outparam_as_reference type traits. These type traits may be specialized for// types other than raw pointers to allow calling functions with argument types typename U, typename... XArgs, typename... Args, typename = std:: -> to_result_retval_t<R, E, outpa, Func,Args.. { typename = decltype(*std: return ToResultInvokeInternal,E(
<T>& aObj,
nsresult (U::*aFunc)(java.lang.StringIndexOutOfBoundsException: Range [0, 52) out of bounds for length 36 returnjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 38
}
template java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
* Adapts a function* output parameter as typename = std::enable_if_t<std::is_base_of_v<U, T>>, typename = decltype(*std::declval<const SmartPtr<T>>())> auto ToResultInvokeMember(const SmartPtr<const T>& aObj,
nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) { return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
// 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), \
&::mozilla::detail::DerefedType<decltype(obj)>::methodname __VA_OPT__( \
, ) __VA_ARGS__)
// 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 MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(resultType, obj, methodname, ...) \
::mozilla::ToResultInvoke<MOZ_REMOVE_PAREN(resultType)>( \
::std::mem_fn( \
&::mozilla::detail::DerefedType<decltype(obj)>::methodname), \
(obj)__VA_OPT__(, ) __VA_ARGS__)
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.