小编Nik*_*dig的帖子

MSVC 中的 type_info 编译器错误?

所以我有这个代码:

#include <typeinfo>
#include <iostream>

void thing(char thing[2], int thing2) {

}

void thing2(char* thing, int thing2) {

}

template <typename T, typename U>
struct are_types_same {
    constexpr operator bool() const noexcept { return false; }
};

template <typename T>
struct are_types_same<T, T> {
    constexpr operator bool() const noexcept { return true; }
};

int main() {
    const std::type_info& info = typeid(thing);
    const std::type_info& info2 = typeid(thing2);

    std::cout << "typeid: " << (info == info2) << '\n';
    std::cout << "are_types_same: …
Run Code Online (Sandbox Code Playgroud)

c++ templates types clang visual-c++

7
推荐指数
1
解决办法
140
查看次数

Shift + Backspace 在 Windows 版 Vim 上不起作用

在您将此问题标记为双重问题之前,请先听我说完,因为我环顾四周,找不到任何可以解决我的问题的内容。

\n

在 Windows 版 Vim 中(通过控制台中的 CMD 运行的 Powershell 访问),退格键工作正常。按 Shift(或 Ctrl)+ Backspace 会在屏幕上打印一个看起来很奇怪的 I,然后按 Ctrl+C。

\n

使用 :set 查看 Vim 上退格键的键码,结果是:“\xc3\x8e^Cx”。考虑到上述行为,这是有道理的。有趣的是,这个键码显然适用于普通的退格键。然而,我的问题在正常按退格键时不会出现,考虑到正常的键码是这个奇怪的字符集合,这对我来说没有意义。仅当退格键与 Shift 键组合使用时才会出现。

\n

我不明白为什么退格键不发送 ^H 或 ^?。我听说这两种选择很受欢迎。我认为我的终端以某种方式搞砸了,但我不明白为什么当按下 Shift 键时它会发送不同的退格键代码。

\n

提前致谢。

\n

windows vim

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

摆脱 C++ 中令人讨厌的函数类型的可能方法?

所以我最近接触到了C++中所谓的“令人厌恶的函数类型”的怪诞(据我所知源自这篇论文:https ://www.open-std.org/jtc1/sc22/wg21/文档/论文/2015/p0172r0.html)。我想了一会儿,它似乎确实有一定的道理,但如果有人以某种方式将它们从语言中完全删除,一切都会变得更加干净和更令人满意。

也许还有其他来源,但是(至少对我来说)令人讨厌的函数类型的大多数问题都来自于处理成员函数。如果我想获取成员函数的类型,我会这样做:

template <typename T>
struct remove_ptr_to_member { using type = T; };

template <typename T, typename class_t>
struct remove_ptr_to_member<T class_t::*> { using type = T; };

struct container {
   void func() const;
};

using member_function_type = typename remove_ptr_to_member<decltype(container::func)>::type;
Run Code Online (Sandbox Code Playgroud)

const由于的声明中存在 a func(),删除指向成员的指针部分会给我们留下一个令人讨厌的函数。

this如果将不可见参数放入成员函数的类型中,则可以避免这种情况。然后,通常会导致令人讨厌的函数的东西都将应用于参数thisconst意味着一个const this指针,&&意味着对 实例的右值引用this,等等......)。

现在,即使删除类型的指向成员的指针部分,剩下的也只是完全正常的函数类型。这样做的好处是,它会减少您在实现诸如is_function.

经典方法:

// primary template
template<class>
struct is_function : std::false_type { };
 
// specialization for regular functions …
Run Code Online (Sandbox Code Playgroud)

c++ templates metaprogramming function function-qualifier

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