Skip to content

Commit

Permalink
[0.73] C++ 20: Fix `Explicit template specialization cannot have a st…
Browse files Browse the repository at this point in the history
…orage class` (#12328) (#13681)

* C++ 20: Fix `Explicit template specialization cannot have a storage class` (#12328)

* C++ 20: Fix "Explicit template specialization cannot have a storage class"

Fixes "[Explicit template specialization cannot have a storage class](https://stackoverflow.com/questions/29041775/explicit-template-specialization-cannot-have-a-storage-class-member-method-spe)" in C++ 20 by moving a function outside of a struct.

* Change files

* Update change file type
  • Loading branch information
vmoroz authored Sep 9, 2024
1 parent b35c4ca commit 38be74a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "C++ 20: Fix \"Explicit template specialization cannot have a storage class\"",
"packageName": "react-native-windows",
"email": "ngerlem@fb.com",
"dependentChangeType": "patch"
}
30 changes: 15 additions & 15 deletions vnext/Microsoft.ReactNative.Cxx/NativeModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ struct MethodSignatureMatchResult {
bool IsSucceeded;
};

template <class TInputArg, class TOtherInputArg>
constexpr bool MatchInputArg() noexcept {
return std::is_same_v<TInputArg, TOtherInputArg>;
}

template <>
constexpr bool MatchInputArg<std::wstring, std::string>() noexcept {
return true;
}

template <>
constexpr bool MatchInputArg<std::string, std::wstring>() noexcept {
return true;
}

template <class TResult, class TInputArgs, class TOutputCallbacks, class TOutputPromises>
struct MethodSignature {
using Result = TResult;
Expand All @@ -375,21 +390,6 @@ struct MethodSignature {
}
}

template <class TInputArg, class TOtherInputArg>
static constexpr bool MatchInputArg() noexcept {
return std::is_same_v<TInputArg, TOtherInputArg>;
}

template <>
static constexpr bool MatchInputArg<std::wstring, std::string>() noexcept {
return true;
}

template <>
static constexpr bool MatchInputArg<std::string, std::wstring>() noexcept {
return true;
}

template <class TOtherInputArgs, size_t... I>
static constexpr bool MatchInputArgs(std::index_sequence<I...>) noexcept {
return (MatchInputArg<std::tuple_element_t<I, InputArgs>, std::tuple_element_t<I, TOtherInputArgs>>() && ...);
Expand Down

0 comments on commit 38be74a

Please # to comment.