2011-12-07 2 views
1

비동기 표준으로 unique_ptr을 복용하는 함수를 :: 호출 :내가 GCC 4.6.2와 <code>unique_ptr</code>을 허용하는 기능을 실행 <code>std::async</code>을 얻으려고

#include <type_traits> 
#include <memory> 
#include <functional> 
#include <future> 

struct Foo {}; 

// my gcc does not have this, same definition as in 30.2.6 
template<typename T> 
typename std::decay<T>::type decay_copy(T&& v) { return std::forward<T>(v); } 

int main() { 
    std::function<int(std::unique_ptr<Foo>)> f = [](std::unique_ptr<Foo>) { return 23; }; 

    std::unique_ptr<Foo> fp{new Foo}; 
    std::unique_ptr<Foo> fp2{std::move(fp)}; 
    // works, this seems to satisfy the requirements of async 
    f(decay_copy(std::move(fp2))); 

    // does not work with reference to a deleted function 
    // std::async(f, std::move(fp2)); 
} 

하면이 예상되는 동작입니다하거나입니다 gcc 버그?

답변

2

아마도 버그 일 수 있습니다. g ++ 4.7로 컴파일 할 수 있습니다.

관련 문제