简体   繁体   English

使用花括号而不是括号时 Visual Studio 中断

[英]Visual Studio breaks when using curly braces instead of parenthesis

I have the following wrapper of std::make_unique:我有以下 std::make_unique 包装器:

template <typename Element, typename... ArgTypes>
auto makeUnique(ArgTypes&&... arguments) {
  return std::make_unique<Element>(std::forward<ArgTypes>(arguments)...);
}

which is used this way:以这种方式使用:

template <typename F>
static auto createCustomValidator(F &&validator) {
    auto func = [validator = std::forward<F>(validator)](const int val){ return validator(seconds(val)); };
    return makeUnique<property::CustomDoubleValidator<decltype(func)>>( std::move(func) );
}

Previous versions of Visual Studio accepted the following:以前版本的 Visual Studio 接受以下内容:

return makeUnique<property::CustomDoubleValidator<decltype(func)>>{ std::move(func) };

(notice the curly braces around std::move) (注意 std::move 周围的花括号)

Visual Studio 16.5 breaks this and can only be fixed with parenthesis instead of curly braces. Visual Studio 16.5 打破了这一点,只能用括号而不是花括号来修复。 Which one is correct?哪一个是正确的?

makeUnique<property::CustomDoubleValidator<decltype(func)>> is a function, so it must be called with parentheses. makeUnique<property::CustomDoubleValidator<decltype(func)>>是一个 function,所以必须用括号调用。 The right answer is definitely parentheses.正确的答案肯定是括号。

It may be the case that previous versions of Visual Studio accepted curly braces as an extension.可能是以前版本的 Visual Studio 接受大括号作为扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM