auto在(可能)用C++ 17引入的模板参数中有哪些优点?
它只是auto我想要实例化模板代码的自然扩展吗?
auto v1 = constant<5>; // v1 == 5, decltype(v1) is int
auto v2 = constant<true>; // v2 == true, decltype(v2) is bool
auto v3 = constant<'a'>; // v3 == 'a', decltype(v3) is char
Run Code Online (Sandbox Code Playgroud)
我还从这个语言功能中获得了什么?
此constexpr代码未在Visual Studio 2013版本12.0.21005.1 REL中编译
是否有更新的Visual Studio编译器与constexpr一起使用?
#include <iostream>
constexpr int factorial(int n)
{
return n <= 1 ? 1 : (n * factorial(n - 1));
}
int main(void)
{
const int fact_three = factorial(3);
std::cout << fact_three << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译输出:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1> Source.cpp
1>....\source.cpp(3): error C2144: syntax error : 'int' should be preceded by ';'
1>....\source.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ … 当我使用 xmltodict 加载下面的 xml 文件时,出现错误: xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 1
这是我的文件:
<?xml version="1.0" encoding="utf-8"?>
<mydocument has="an attribute">
<and>
<many>elements</many>
<many>more elements</many>
</and>
<plus a="complex">
element as well
</plus>
</mydocument>
Run Code Online (Sandbox Code Playgroud)
来源:
import xmltodict
with open('fileTEST.xml') as fd:
xmltodict.parse(fd.read())
Run Code Online (Sandbox Code Playgroud)
我在 Windows 10 上,使用 Python 3.6 和 xmltodict 0.11.0
如果我使用 ElementTree 它可以工作
tree = ET.ElementTree(file='fileTEST.xml')
for elem in tree.iter():
print(elem.tag, elem.attrib)
mydocument {'has': 'an attribute'}
and {}
many {}
many {}
plus {'a': 'complex'}
Run Code Online (Sandbox Code Playgroud)
注意:我可能遇到了换行问题。
注2:我在两个不同的文件上使用了Beyond Compare。
它在 UTF-8 …
在我的客户端 PC 上加载 my.xll 插件时,我遇到了问题。它在启动时崩溃 Excel(可能是因为缺少依赖的 dll)。
我知道可以在配置文件模式下使用依赖项walker来找出.exe运行时加载了哪些dll。当我尝试分析 Excel 时,依赖项walker 挂起,但我找不到原因。
在命令窗口中,我运行了这个:
C:\Program Files (x86)\Windows Kits\8.1\Tools\x86>start /wait depends.exe /c /f:1 /pb /pp:1 /pg:1 /oc:d:\temp\Log。 txt "C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"
我使用的是 Dependency walker 版本 2.2.9600 x86、Windows 8.1 x86、office 2010 x86
我还尝试使用全新安装的 win 8.1 和 Office 2010 来设置 VM 机器,但是当我加载 .xll 时,XL 不会在该机器上崩溃。
我在另一台机器 Windows 10 x64、office 2013 x64 和dependency walker x64 上工作。我可以分析 Excel。
注意:我最终使用了 Sysinternals Process Explorer。有点复杂,但有效。
我在关于匿名方法(C#编程指南)的MSDN文档中阅读本文,但我不理解省略参数列表的部分.它说:
有一种情况是匿名方法提供lambda表达式中找不到的功能.匿名方法使您可以省略参数列表.这意味着可以将匿名方法转换为具有各种签名的委托.lambda表达式无法做到这一点.
你能举一个省略匿名方法参数列表的例子吗?
在 Visual Studio 2017 中,当我重新加载解决方案时会冻结。当我查看任务管理器时,我可以看到进程 Microsoft.Alm.Shared.Remoting.RemoteContainer.dll(32 位)正在占用我的所有核心(请参见屏幕截图)。我尝试禁用 CodeLens,重新启动 VS,然后打开 CodeLens 位,问题仍然存在。

我正在使用 Visual Studio 2017 professional 15.5.2
我的操作系统是 Windows 10 版本 1709 build 16299.15。
我可以看到这个问题在2013年就被报道过,而且似乎还没有得到解决。
我应该关闭 CodeLens 因为我只编程 C++ 吗?
更新:我关闭了 CodeLense,问题仍然存在。
Update2:我尝试按照 magicandre1981 的建议运行性能分析(谢谢!),但不幸的是,Microsoft 的符号服务器上似乎没有 .dll 的任何调试符号。我确实加载了符号。
正如论文P0409R2中提出的
我期望 x 的定义从 C++20 中被弃用并且无法编译,但它似乎可以在 g++ (GCC) 8.1.0 中工作,有谁知道我是否做错了什么?
在 Visual Studio 2017 中,编译器失败,并在 y 的定义周围出现错误。错误 C3791:当默认捕获模式为复制 (=) 时,无法显式捕获“this”
#include <iostream>
struct X {
void f()
{
int value = 3;
auto x = [=] { // Deprecated from C++20:
return value + g();
};
auto y = [=, this] { // Recommended method from C++20:
return value + g(); // [=] The this pointer will not be captured, so capture with specifying this
};
} …Run Code Online (Sandbox Code Playgroud) 当我在Visual Studio 2015中编译它时出现错误:错误C2398:元素'1':从'double'转换为'float'需要缩小转换
vector<float> v {2.46, 2.58, 2.0, 2.25, 3.0 };
Run Code Online (Sandbox Code Playgroud)
但这很有效
vector<float> v{ (float)2.46, (float)2.58, (float)2.0, (float)2.25, (float)3.0 };
Run Code Online (Sandbox Code Playgroud)
这个代码是否有一个优雅的解决方案,所以我不必将所有输入都浮动?也许调整initializer_list?
当我尝试设置断点时,什么也没有发生;我将光标放在该println!行上并按F9。
fn main() {
println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)
我在另一台安装了 Visual Studio 2017 的机器上工作,所以我怀疑这可能是问题所在。
任务文件
fn main() {
println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)
启动文件
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cargo build",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"clear": true
},
"problemMatcher": {
"owner": "rust",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.+):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": …Run Code Online (Sandbox Code Playgroud) 可以isize和USIZE有所不同呢?它们都可以用于内存大小、索引、偏移量。
既然usize用于数组,为什么我们不只有 usize
我是 Rust 的新手,所以这可能是一个基本问题。
更新:在 32 位系统上,它们都是 32 位长,在 64 位系统上它们都是 64 位长。与标志无关。
c++ ×4
c++11 ×2
rust ×2
windows-10 ×2
auto ×1
c# ×1
c++17 ×1
c++20 ×1
constexpr ×1
depends ×1
dll ×1
freeze ×1
lambda ×1
office-2010 ×1
python-3.x ×1
templates ×1
windows-8.1 ×1