与一起编译,/permissive但与一起失败/permissive-。什么不符合以及如何解决?
为什么很好,(2)但失败了?如果我删除它也很好。(4)(3)operator long
如何在不更改呼叫站点的情况下进行修复(3,4)?
#include <string>
struct my
{
std::string myVal;
my(std::string val): myVal(val) {}
operator std::string() { return myVal; };
operator long() { return std::stol(myVal); };
};
int main()
{
struct MyStruct
{
long n = my("1223"); // (1)
std::string s = my("ascas"); // (2)
} str;
str.s = my("ascas"); // (3)
str.n = my("1223"); // (4)
}
Run Code Online (Sandbox Code Playgroud)
错误信息
error C2593: 'operator =' is ambiguous
xstring(2667): note: could …Run Code Online (Sandbox Code Playgroud) c++ visual-c++ implicit-conversion move-constructor move-assignment-operator
为什么 Roslyn 编译器生成带有internal访问修饰符(在 IL 中,assembly)而不是 的本地函数private?
private void M()
{
bool f = true;
bool x1() => f;
static bool x2() => true;
}
Run Code Online (Sandbox Code Playgroud)
.method assembly hidebysig static
bool '<M>g__x1|0_0' (
valuetype C/'<>c__DisplayClass0_0'& ''
) cil managed { ... }
.method assembly hidebysig static
bool '<M>g__x2|0_1' () cil managed { ... }
Run Code Online (Sandbox Code Playgroud)
文档说它应该是私有的: https: //learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions
本地函数是嵌套在另一个成员中的类型的私有方法。
由于所有本地函数都是私有的,包括访问修饰符(例如 private 关键字),会生成编译器错误 CS0106
std::string s = "y";
s = "x" + std::move(s) + "x";
Send(std::move(s));
Run Code Online (Sandbox Code Playgroud)
Microsoft STL 实现会对此进行检查,但标准是否强制要求这样做?
它看起来比插入+附加或两个变量方法更干净。
注意:我知道我可以做到Send(std::move("x" + std::move(s) + "x")),但真正的代码并不那么简单。
为什么它有效?
#include <cstdio>
template<auto x> struct constant {
constexpr operator auto() { return x; }
};
constant<true> true_;
static constexpr const bool true__ = true;
template<auto tag> struct registryv2 {
// not constexpr
static auto push() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
//*
return true_; // compiles
/*/
return true__; // read of non-const variable 'x' is not allowed in a constant expression
//*/
}
// not constexpr either
static inline auto x = push();
};
static_assert(registryv2<0>::x);
Run Code Online (Sandbox Code Playgroud)
我正在编写Angular 2 Universal app,所以我不想要任何DOM类型.但我想编译目录中的所有文件,所以设置"file"的tsconfig.json是不能接受的.
如何在不获取对象的情况下获取远程引用列表(仅名称和提交 ID)?
WebUI 显然不是答案。
我发现的只是远程HEAD名称:
$ git remote -v show origin
* remote origin
Fetch URL: https://git.git
Push URL: https://git.git
HEAD branch: main
Remote branch:
refs/remotes/origin/master stale (use 'git remote prune' to remove)
Local branch configured for 'git pull':
master merges with remote master
Run Code Online (Sandbox Code Playgroud)