gpt4 book ai didi

c++ - 变量 '...' 周围的堆栈已损坏

转载 作者:太空狗 更新时间:2023-10-29 22:55:13 25 4
gpt4 key购买 nike

在 Debug模式下的 MSVC 15.8.5 上,我明白了

Run-Time Check Failure #2 - Stack around the variable 'insert_into' was corrupted.

是 MSVC 中存在错误还是我做错了什么?

在 clang 版本 6.0.0-1ubuntu2 和 clang 版本 7.0.0-svn341916-1~exp1~20180911115939.26 上运行良好

#include <set>

template <typename... T>
struct Overload : T...
{
//support struct for combining and overloading multiple lambdas
using T::operator()...;
};
template <typename... T>
Overload(T...)->Overload<T...>;

using BuiltSet = std::set<std::string>;

template <typename... Args>
BuiltSet MakeBuildSet(const Args&... args)
{
//takes a list of arguments if an argument is a
// BuiltSet each element is added to headers,
// otherwise the arg itself is added to headers
BuiltSet headers{};

//Construct a lambda with overloading on if argument is a BuiltSet or not
const Overload insert_into{
[](const BuiltSet& h, BuiltSet& headers) {
headers.insert(h.begin(), h.end());
},
[](const auto& arg, BuiltSet& headers) {
headers.insert(arg);
}
};
//Fold over arguments applying the lambda on each element
(insert_into(args, headers), ...);
return headers;
}

int main(int argc, char** argv)
{
MakeBuildSet(MakeBuildSet("a", "b", "c"), "a", "b", "c");
return 0;
}

最佳答案

MSVC bug所以这是编译器的一个缺陷。

关于c++ - 变量 '...' 周围的堆栈已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52833810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com