小编smi*_*hax的帖子

decltype(function)作为类成员

我有:

int foo(int x) { return x+1; }

struct Bar {
  decltype(foo) operator();
};

int main() {
  Bar bar;
  printf("%d\n",bar(6));
}
Run Code Online (Sandbox Code Playgroud)

这会导致稍微令人吃惊的编译器错误消息(g ++ 4.6.1):

error: declaration of 'operator()' as non-function
Run Code Online (Sandbox Code Playgroud)

将成员名称更改为时

  decltype(foo) blubb;
Run Code Online (Sandbox Code Playgroud)

并使用它会导致链接器错误:

undefined reference to `Bar::blubb(int)'
Run Code Online (Sandbox Code Playgroud)

这是预期的行为吗?

c++ compiler-errors linker-errors decltype c++11

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

std :: is_signed <T>和std :: numeric_limits <T> :: is_signed之间的区别?

双方std::is_signed<T>std::numeric_limits<T>::is_signed应该提供有关的符号性的答案T.
为什么现在有两个签名指标(即自C++ 11以来)?

c++ std numeric-limits c++11

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

布尔值之间的 SQL less/greater 比较会产生意外结果

为什么大多数(全部?)SQL 数据库给出:

SELECT FALSE < FALSE;      -- FALSE / 0   Ok
SELECT TRUE < FALSE;       -- FALSE / 0   Ok

SELECT NOT(FALSE) < FALSE; -- TRUE / 1    What?
SELECT NOT(TRUE) < FALSE;  -- TRUE / 1    What??
Run Code Online (Sandbox Code Playgroud)

只需仔细检查即可:

SELECT NOT(TRUE) = FALSE;  -- TRUE / 1    Ok
SELECT NOT(FALSE) = TRUE;  -- TRUE / 1    Ok
Run Code Online (Sandbox Code Playgroud)

在 Postgres 中,我还可以检查:

SELECT pg_typeof(TRUE), pg_typeof(NOT(FALSE));
  -- boolean | boolean
Run Code Online (Sandbox Code Playgroud)

我已经在 PostgreSQL、SQLite3 和 MariaDB 上尝试过这一点,并且都同意相同的意外结果。
我缺少什么?

mysql sql sqlite postgresql mariadb

5
推荐指数
3
解决办法
106
查看次数

decltype(*&fun)很奇怪?

我有:

#include <type_traits>
#include <stdio.h>

void f() { printf("foo\n"); }

int main()
{
  printf("%d %d %d\n",
    std::is_same<decltype(*&f),decltype(f)>::value,
    std::is_function<decltype(*&f)>::value,
    std::is_function<decltype(f)>::value);
  (*&f)();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

产量

0 0 1
foo
Run Code Online (Sandbox Code Playgroud)

在g ++ 4.6.1和4.7.0上.

任何人都可以向我解释这个吗?

c++ g++ decltype c++11

4
推荐指数
1
解决办法
255
查看次数