ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

combine_latest fails build with MSVC 19.34.31935.0 when C++ standard is set to 17 #596

Open juhanisimola-yousician opened 1 year ago

juhanisimola-yousician commented 1 year ago

Reproduction steps:

The build fails with long, long error message starting with

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\utility(491,62): error C2027: use  of undefined type 'std::tuple_size<_Ty>' [Z:\work\RxCpp\projects\CMake\cmake-build-vs-std17\test\rxcpp_test_combine_latest.vcxpro j]
          with
          [
              _Ty=rxcpp::util::detail::surely
          ]
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\utility(491,45): message : see de claration of 'std::tuple_size<_Ty>' [Z:\work\RxCpp\projects\CMake\cmake-build-vs-std17\test\rxcpp_test_combine_latest.vcxproj]
          with
          [
              _Ty=rxcpp::util::detail::surely
          ]
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\tuple(886,29): message : see refe rence to variable template 'const size_t tuple_size_v<rxcpp::util::detail::surely>' being compiled [Z:\work\RxCpp\projects\CMake\c make-build-vs-std17\test\rxcpp_test_combine_latest.vcxproj]
Z:\work\RxCpp\Rx\v2\src\rxcpp\rx-observer.hpp(119,1): message : see reference to function template instantiation 'auto rxcpp::oper ators::detail::combine_latest<rxcpp::identity_one_worker,ResolvedSelector,rxcpp::observable<copy_verifier,rxcpp::dynamic_observabl e<T>>,rxcpp::observable<int,rxcpp::sources::detail::iterate<std::array<int,1>,rxcpp::identity_one_worker>>>::subscribe_one::<lambd a_bcf9f84f11f0b5575b8d9322f6074035>::operator ()<copy_verifier>(copy_verifier &&) const' being compiled [Z:\work\RxCpp\projects\CM ake\cmake-build-vs-std17\test\rxcpp_test_combine_latest.vcxproj]
          with
          [
              ResolvedSelector=C_A_T_C_H_T_E_S_T_185::<lambda_d6e91046af7606d56dd145e6479e9d93>,
              T=copy_verifier
          ]
Z:\work\RxCpp\Rx\v2\src\rxcpp/operators/rx-combine_latest.hpp(136,1): message : see reference to class template instantiation 'rxc pp::detail::is_on_next_of<source_value_type,rxcpp::operators::detail::combine_latest<rxcpp::identity_one_worker,ResolvedSelector,r xcpp::observable<copy_verifier,rxcpp::dynamic_observable<T>>,rxcpp::observable<int,rxcpp::sources::detail::iterate<std::array<int, 1>,rxcpp::identity_one_worker>>>::subscribe_one::<lambda_bcf9f84f11f0b5575b8d9322f6074035>>' being compiled [Z:\work\RxCpp\project s\CMake\cmake-build-vs-std17\test\rxcpp_test_combine_latest.vcxproj]
          with
          [
              ResolvedSelector=C_A_T_C_H_T_E_S_T_185::<lambda_d6e91046af7606d56dd145e6479e9d93>,
              T=copy_verifier
          ]
Z:\work\RxCpp\Rx\v2\src\rxcpp\rx-subscriber.hpp(786,6): message : see reference to function template instantiation 'std::enable_if <rxcpp::detail::is_on_next_of<T,Observer>::value&&rxcpp::detail::is_on_error<OnError>::value&&rxcpp::detail::is_on_completed<OnCom pleted>::value,rxcpp::subscriber<T,rxcpp::observer<T,rxcpp::detail::stateless_observer_tag,OnNext,OnError,OnCompleted>>>::type rxc pp::make_subscriber(const rxcpp::subscriber<OtherT,OtherObserver> &,const rxcpp::composite_subscription &,const OnNext &,const OnE rror &,const OnCompleted &)' being compiled [Z:\work\RxCpp\projects\CMake\cmake-build-vs-std17\test\rxcpp_test_combine_latest.vcxp roj]

Build is successful using C++ standards 11 and 14, but not 17. There are other errors when attempting to build with Clang, but this part can be successfully built.

xiaoxiaok commented 1 year ago

Add util to apply in surely may fix this problem just as following

template<class... T>
inline auto surely(const std::tuple<T...>& tpl)
    -> decltype(util::apply(tpl, detail::surely())) {
    return      util::apply(tpl, detail::surely());
}
juhanisimola-yousician commented 1 year ago

Thanks, that worked.

juhanisimola-yousician commented 1 year ago

I fixed this and some Clang issues at https://github.com/YousicianGit/RxCpp/pull/1/files