1

Visual Studio (Nov '12 CTP) を使用して一部のコードをコンパイルすると、次のエラーが発生します。

1>c:\users\*\documents\visual studio 2012\projects\consoleapplication2\consoleapplication2\main.cpp(19): error C2893: Failed to specialize function template 'unknown-type locked_call(Lockable &,Callable,Args &&...)'
1>          With the following template arguments:
1>          'std::mutex'
1>          'main::<lambda_d4c412a6f5bd8d382f54c74dc3b1ff5d>'
1>          ''

これが私の機能の短い例です:

#include <mutex>
#include <utility>

template <class Lockable, class Callable, typename... Args>
auto locked_call(Lockable &mtx, Callable fn, Args &&... args)
    -> decltype(fn(std::forward<Args>(args)...))
{
    std::lock_guard<Lockable> hold(mtx);
    return fn(std::forward<Args>(args)...);
}

int main()
{
    std::mutex mtx;

    locked_call(mtx, [&] {
    });
}

私の質問は次のとおりです。なぜこれはコンパイルされないのですか? 末尾の戻り値の型、Variadic テンプレート、および decltype はすべて VS11 でサポートされていますが、コンパイラは関数呼び出しの結果の型を取得できないようです。

4

0 に答える 0