考虑这个相当无用的程序:
#include <iostream>
int main(int argc, char* argv[]) {
int a = 5;
auto it = [&](auto self) {
return [&](auto b) {
std::cout << (a + b) << std::endl;
return self(self);
};
};
it(it)(4)(6)(42)(77)(999);
}
Run Code Online (Sandbox Code Playgroud)
基本上我们正在尝试制作一个返回自己的lambda.
error: function 'operator()<(lambda at lam.cpp:6:13)>' with deduced return type cannot be used before it is defined
哪个编译器是对的?是否存在静态约束违规,UB或两者都没有?
clang接受更新此轻微修改:
auto it = [&](auto& self, auto b) {
std::cout << (a + b) << std::endl;
return [&](auto p) { return …Run Code Online (Sandbox Code Playgroud) 我刚刚在一个函数中找到了这行代码,这让我很困惑.这在任何情况下都有意义,还是未定义的行为?
char * acFilename = acFilename;
Run Code Online (Sandbox Code Playgroud)
编辑:编译器抱怨警告C4700,我正在使用未初始化的变量.
int test[2] = { 45, test[0] };
int x = (x = 111);
cout << test[0] << " " << test[1] << " " << x << "\n"; // 45 45 111
Run Code Online (Sandbox Code Playgroud)
前两行的作业是否合法?Visual Studio 2010编译并运行它没有任何错误或警告但似乎奇怪的情况可能是未定义的,所以我想确认它是可以接受的.Visual Studio会警告我,如果我做了一些公然反身(并且可能是未定义的),int x = x;那么我想知道这些情况似乎是如何处理的.
几天前我在"C#匿名递归"中浏览了这个网站.本文的主旨是以下代码在C#中不起作用:
Func<int, int> fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : n;
Run Code Online (Sandbox Code Playgroud)
然后,文章详细介绍了如何使用currying和Y-combinator回到C#中的"Anonymous Recursion".这很有趣,但我担心日常编码有点复杂.此时至少......
我喜欢看自己的东西,所以我打开了Mono CSharp REPL并输入了该行.没有错误.所以,我进来了fib(8);.令我非常惊讶的是,它奏效了!REPL回复了21!
我想也许这可能是REPL的一些魔力,所以我点了'vi',输入以下程序,然后编译它.
using System;
public class Program
{
public static void Main(string[] args)
{
int x = int.Parse(args[0]);
Func<int, int> fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : n;
Console.WriteLine(fib(x));
}
}
Run Code Online (Sandbox Code Playgroud)
它也完美地建造和运行!
我在Mac上运行Mono 2.10.我现在无法访问Windows计算机,所以我无法在Windows上的.NET上进行测试.
这是在.NET上修复过的还是Mono的静音功能?这篇文章已经有几年了.
如果它只是单声道,我不能等待下一次面试,他们要求我用我选择的语言(Mono …
// bind function:
template<typename T> T bind(T& v)
{
// Can I toy with the object v refers to? or that's undefined behaviour?
// the object v refers to is not initialized yet, But the object has been allocated, so I can use that memory, I think?
// The following 2 lines should be fine if I'm correct.
// Which is my function is currently is doing (sorta)
myvector.emplace_back(SQLType<T>(), (void*)&v);
return 0;
}
SomeClass value = bind(value);
Run Code Online (Sandbox Code Playgroud)
我想知道我是否可以value在初始化之前使用该对象(当 …