小编Mat*_*att的帖子

在R6RS Scheme中,有没有办法让当前环境与eval一起使用?

在R6RS Scheme中是否有任何方法可以获取当前环境,然后将其作为第二个参数传递给eval

例如,下面的表达式返回9时问号应该是什么?

(let ((x 4)
      (y 5))
  (eval '(+ x y) ???))
Run Code Online (Sandbox Code Playgroud)

environment scheme eval r6rs

6
推荐指数
1
解决办法
570
查看次数

反正是否基于C++中的参数成员专门化模板?

有没有专门化这样的模板,只有T有成员函数才能使专业化适用hash?(注意这只是我想要做的一个例子.我知道对于每个具有hashoperator==成员函数中自己检查它的函数的类会更有意义,但我只是想知道这种类型事情是可能的.)

template <class T>
bool equals(const T &x, const T &y)
{
    return x == y;
}

template <class T> // somehow check if T has a member function 'hash'
bool equals<T>(const T &x, const T &y)
{
    return x.hash() == y.hash() && x == y;
}
Run Code Online (Sandbox Code Playgroud)

如果可能的话,我更喜欢预C++ 11解决方案.

c++ templates template-specialization template-meta-programming

6
推荐指数
1
解决办法
210
查看次数

在WPF中,有没有办法使StackPanel像Grid一样对齐列?

例如,我可以这样做:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Width="Auto">
        <RowDefinition Width="Auto">
        <RowDefinition Width="Auto">
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" Grid.Column="0">Header 1</TextBlock>
    <TextBox Grid.Row="0" Grid.Column="1" MaxLines="1" />
    <Button Grid.Row="0" Grid.Column="2">Send</Button>
    <Button Grid.Row="0" Grid.Column="3">Save</Button>
    <TextBlock Grid.Row="1" Grid.Column="0">Header 2</TextBlock>
    <TextBox Grid.Row="1" Grid.Column="1" MaxLines="1" />
    <Button Grid.Row="1" Grid.Column="2">Send</Button>
    <Button Grid.Row="1" Grid.Column="3">Save</Button>
    <TextBlock Grid.Row="2" Grid.Column="0">Header 3</TextBlock>
    <TextBox Grid.Row="2" Grid.Column="1" MaxLines="1" />
    <Button Grid.Row="2" Grid.Column="2">Send</Button>
    <Button Grid.Row="2" Grid.Column="3">Save</Button>
</Grid>
Run Code Online (Sandbox Code Playgroud)

或者我可以这样做:

<StackPanel>
    <StackPanel Orientation="Horizontal">
        <TextBlock>Header 1</TextBlock>
        <TextBox MaxLines="1" />
        <Button>Send</Button> …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf grid stackpanel

6
推荐指数
1
解决办法
1万
查看次数

种子srand()的最佳方法是什么?

我学习的方法是初始播种随机数生成器,srand(time(NULL))然后使用调用rand()生成随机数.这种方法的问题是如果我在同一秒内多次运行我的程序,生成的随机数将始终相同.这有什么好办法?

c random srand

6
推荐指数
2
解决办法
1万
查看次数

将字符串返回到SWIG python接口的最佳方法是什么?

什么是线程安全且无内存泄漏的方法将字符串从C++返回到SWIG python接口?

SWIG会自动将char *返回值的内容复制到python字符串中.这个SWIG指南给出了一个例子:

char *__str__() {
    static char temp[256];
    /* WRITE STUFF TO STRING */
    return &temp[0];
}
Run Code Online (Sandbox Code Playgroud)

他们的示例使用静态字符串作为返回值,但如果我的C++程序有多个线程,它们可以轻松覆盖彼此的字符串.

返回新分配的字符串会产生内存泄漏,因为SWIG不知道要释放它.

我唯一能想到的就是注册并返回一个指向实际python字符串对象的指针(这样python垃圾收集器会照顾它),但我不知道该怎么做,我想知道是否有更简单的方法.

c++ python string swig memory-management

6
推荐指数
1
解决办法
1552
查看次数

为什么io.WriterTo的WriteTo方法返回int64而不是int?

大部分的输出方法Go的io的回报(int, error),例如io.WriterWrite([]byte)方法和io.WriteString(io.Writer, string)功能.然而,少数的输出方法,如io.WriterToWriteTo方法,返回(int64, error)来代替.这使得不方便实现WriteTo在以下方面WriteWriteString不存储的中间值,并输入从将其转换intint64.造成这种差异的原因是什么?

io standard-library go output

6
推荐指数
2
解决办法
450
查看次数

关于gcc编译的x86_64代码和C代码优化

我编译了以下C代码:

typedef struct {
    long x, y, z;
} Foo;

long Bar(Foo *f, long i)
{
    return f[i].x + f[i].y + f[i].z;
}
Run Code Online (Sandbox Code Playgroud)

用命令gcc -S -O3 test.c.这是输出中的Bar函数:

    .section    __TEXT,__text,regular,pure_instructions
    .globl  _Bar
    .align  4, 0x90
_Bar:
Leh_func_begin1:
    pushq   %rbp
Ltmp0:
    movq    %rsp, %rbp
Ltmp1:
    leaq    (%rsi,%rsi,2), %rcx
    movq    8(%rdi,%rcx,8), %rax
    addq    (%rdi,%rcx,8), %rax
    addq    16(%rdi,%rcx,8), %rax
    popq    %rbp
    ret
Leh_func_end1:
Run Code Online (Sandbox Code Playgroud)

关于这个汇编代码,我有几个问题:

  1. " pushq %rbp"," movq %rsp, %rbp"和" popq %rbp" 的目的是什么,如果既没有rbp也没有rsp在函数体中使用?
  2. 为什么rsi …

c optimization x86 gcc x86-64

5
推荐指数
1
解决办法
649
查看次数

C++中'和','或'等关键字的目的是什么?

以下关键字的目的是什么?

and      bitand   compl   not_eq   or_eq   xor_eq
and_eq   bitor    not     or       xor
Run Code Online (Sandbox Code Playgroud)

如果他们只是直接相当于:

&&       &        ~       !=       |=      ^=
&=       |        !       ||       ^
Run Code Online (Sandbox Code Playgroud)

c++ operators keyword operator-keyword

5
推荐指数
2
解决办法
279
查看次数

“kill 0”和“kill -?- -$$”有什么区别?

基本上我想要一个 bash 脚本进程在收到 后SIGINT,在退出之前终止其所有子进程。我在这里读到的内容是:

trap "kill -TERM -$$ ; exit 1" INT QUIT
Run Code Online (Sandbox Code Playgroud)

我还阅读了使用kill 0

trap "kill -TERM 0 ; exit 1" INT QUIT
Run Code Online (Sandbox Code Playgroud)

它们之间有什么区别,它们是否满足以下要求(如果不满足,什么要求?)?:

  1. 仅杀死其自身及其子进程(假设它是由终端命令启动的顶级进程)。
  2. 它不会终止同一 shell 脚本的任何其他进程或实例(从单独的终端命令运行:即运行时./foo.sh &,然后,终止./foo.sh第二个进程或实例,即使在同一个 tty 中,终止第二个进程也不应终止第一个进程)。

linux bash shell process process-group

5
推荐指数
1
解决办法
4669
查看次数

Go是否优化了无法访问的if语句?

Go非常不幸缺乏内置断言.我想以这种方式实现它们:

const ASSERT = true

func SomeFunction() {
        if ASSERT && !some_condition_that_should_always_be_true() {
                panic("Error message or object.")
        }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果我定义if语句会被优化const ASSERT = false吗?

error-handling assert if-statement go

5
推荐指数
1
解决办法
195
查看次数