std::promise where T must be default constructible in Visual Studio 2017?

前端 未结 2 1055
暗喜
暗喜 2021-01-19 07:49

I am trying to compile the following code in Visual Studio 2017:

#include 

int main()
{
    std::promise&         


        
相关标签:
2条回答
  • 2021-01-19 08:31

    I suppose you do not need std::reference_wrapper<int>. There is the suitable overloaded template for std::promise available:

    template<class R> class promise<R&>;
    

    Therefore you can fix your code in Visual Studio 2017:

    #include <future>
    
    int main()
    {
        std::promise<int&> promise;
        (void)promise;
    }
    
    0 讨论(0)
  • 2021-01-19 08:41

    Looks like it is a known issue in MSVC's standard library implementation. A simpler reproduction scenario:

    #include <future>
    struct NoDefaultCtor
    {
        NoDefaultCtor() = delete;
    };
    int main() {
        std::promise<NoDefaultCtor> p;
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题