例如,邪恶是 autoload,
一些博客/线程将使用
(require 'evil)
(evil-mode 1)
Run Code Online (Sandbox Code Playgroud)
启用邪恶模式。
AFAIK,Elisp 是 lisp2,evil-mode也是一个函数,所以不需要setq.
(defadvice evil-mode (after start-evil activate)
"Enable Evil in Fundamental mode."
(if evil-mode
(progn
(when (eq (default-value 'major-mode) 'fundamental-mode)
;; changed back by `evil-local-mode'
(setq-default major-mode 'turn-on-evil-mode))
(ad-enable-regexp "^evil")
(ad-activate-regexp "^evil")
(with-no-warnings (evil-esc-mode 1)))
(when (eq (default-value 'major-mode) 'turn-on-evil-mode)
(setq-default major-mode 'fundamental-mode))
(ad-disable-regexp "^evil")
(ad-update-regexp "^evil")
(with-no-warnings (evil-esc-mode -1))))
Run Code Online (Sandbox Code Playgroud)
但?因为autoload,
(evil-mode 1)
Run Code Online (Sandbox Code Playgroud)
没有require,它也可以正常工作(至少对我而言)
(以下如有不对的地方,请指正,谢谢)
我的问题是require如果需要的包是自动加载的,我什么时候必须使用
我使用ostreambuf_iterator,如下所示:
在c ++ 17之前,
template< class CharT, class Traits = std::char_traits<CharT> >
class ostreambuf_iterator : public std::iterator<std::output_iterator_tag,
void, void, void, void>
Run Code Online (Sandbox Code Playgroud)
要求我们确定std :: iterator的每个参数类型,因此,对于std::ostreambuf_iterator,void并不是那么糟糕.
我们知道, 在c ++ 17中不推荐使用std :: iterator.因此,迭代器应该在自己的主体中键入它们的成员类型,例如:
Member type Definition
---------------------------------------------
value_type void
difference_type void
pointer void
reference void
iterator_category std::output_iterator_tag
Run Code Online (Sandbox Code Playgroud)
题:
为什么这些void类型仍然是typedefed?我想,我想
Member type Definition
---------------------------------------------
iterator_category std::output_iterator_tag
Run Code Online (Sandbox Code Playgroud)
足够.毕竟,弃用的动机std::iterator只是为了简化标准(库).所以应该有一些我无法弄清楚的原因.
另一方面,将其定义为空白可以防止错误,例如:
Run Code Online (Sandbox Code Playgroud)typename Iter::value_type v = *it; //useless with an output iterator if …
这是一个最小的例子:
struct incomplete_type;
template<typename T>
struct foo
{
using type = std::conditional_t<std::is_arithmetic_v<T>,
std::conditional_t<sizeof(T) < sizeof(void*), int, float>,
double>;
};
Run Code Online (Sandbox Code Playgroud)
foo<incomplete_type> f;将导致错误,因为它将使用类型执行sizeof,即使incomplete_type它不是算术类型(哇,它不会逻辑地进入sizeof分支).现场演示
所以,我想推迟 sizeof:
template<typename T>
auto
foo_aux()
{
if(sizeof(T) < sizeof(T*))
return 0;
else
return 0.0f;
}
Run Code Online (Sandbox Code Playgroud)
conditional_t<std::is_arithmetic_v<T>, decltype(foo_aux<T>()), double> 仍会触发相同的错误.
template<typename T, bool>
struct foo_aux_aux
{
using type = float;
};
template<typename T>
struct foo_aux_aux<T, true>
{
using type = int;
};
template<typename T, bool = false>
struct foo_aux : foo_aux_aux<T, …Run Code Online (Sandbox Code Playgroud) c++ type-traits template-meta-programming incomplete-type c++17
似乎有些误解,认为这是为了比赛。我正在尝试完成一项任务,而现在我已经坚持了一个小时。
/*
* isLessOrEqual - if x <= y then return 1, else return 0
* Example: isLessOrEqual(4,5) = 1.
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 24
* Rating: 3
*/
int isLessOrEqual(int x, int y)
{
int greater = (x + (~y + 1))>>31 & 1;
return !(greater)|(!(x^y));
}
Run Code Online (Sandbox Code Playgroud)
如注释中所述,我只能使用按位运算符。我不知道如何解决x <= y;
我的思考过程是,我可以将x设置为它的二进制补码(~x +1),然后将其添加Y。如果为负,X则大于Y。因此,通过否定我可以得到相反的效果。
同样,我知道!(x^y)等同于x==y。但是,这样!(greater)|(!(x^y))做不会返回正确的值。 …
我已经阅读了这些材料:
std::move 和 std::forward 有什么区别
这个答案非常接近我的问题,但一个是setImage,另一个是右值引用构造函数,所以恐怕存在一些微妙的东西。
class ClassRoom
{
private:
vector<string> students;
public:
ClassRoom(vector<string>&& theStudents)
:students{std::forward<vector<string>>(theStudents)}
{
}
}
Run Code Online (Sandbox Code Playgroud)
class ClassRoom
{
private:
vector<string> students;
public:
ClassRoom(vector<string>&& theStudents)
:students{std::move(theStudents)}
{
}
}
Run Code Online (Sandbox Code Playgroud)
有人告诉我这forward是正确的方法,因为 的用法之一forward是将右值引用变量传递给其他人并保证不再使用它。但我不知道为什么不在move这里使用,他说的对吗?
例如
int arr[2][3] = ...
Run Code Online (Sandbox Code Playgroud)
类型arr[0]是
int (*)[3] // pointer to int[3], which is a pointer.
Run Code Online (Sandbox Code Playgroud)
要么
int[3] // an array whose size is 3, which is an array.
Run Code Online (Sandbox Code Playgroud)
谷歌没有告诉我这个问题.
我知道指针和数组是不同的类型(派生类型).
也许C和C++对待它的方式不同,我希望看到标准的措辞.
我们知道,在C++中,我们可以将数组的引用作为参数传递f(int (&[N]).是的,它是iso标准保证的语法,但我很好奇编译器如何在这里工作.我找到了这个帖子,但遗憾的是,这并没有回答我的问题 - 编译器如何实现这种语法?
然后我写了一个演示,希望从汇编语言中看到一些东西:
void foo_p(int*arr) {}
void foo_r(int(&arr)[3]) {}
template<int length>
void foo_t(int(&arr)[length]) {}
int main(int argc, char** argv)
{
int arr[] = {1, 2, 3};
foo_p(arr);
foo_r(arr);
foo_t(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
最初,我猜它仍会衰减到指针,但会通过寄存器隐式传递长度,然后转回函数体中的数组.但汇编代码告诉我这不是真的
void foo_t<3>(int (&) [3]):
push rbp #4.31
mov rbp, rsp #4.31
sub rsp, 16 #4.31
mov QWORD PTR [-16+rbp], rdi #4.31
leave #4.32
ret #4.32
foo_p(int*):
push rbp #1.21
mov rbp, rsp #1.21
sub rsp, 16 #1.21
mov QWORD …Run Code Online (Sandbox Code Playgroud) 这是我将二进制文字转换为十进制的实现:
template<char Head, char... Tail>
constexpr int operator"" _b()
{
if constexpr (sizeof... (Tail) == 0)
{
return Head - '0';
}
else
{
return (Head - '0') * (1 << sizeof...(Tail)) + operator"" _b<Tail...>();
}
}
Run Code Online (Sandbox Code Playgroud)
虽然Clang 失败了:
prog.cc:1:2: error: template parameter list for literal operator must be either 'char...' or 'typename T, T...'
template<char Head, char... Tail>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cc:19:27: error: no matching literal operator for call to 'operator""_b' with argument of type 'unsigned …Run Code Online (Sandbox Code Playgroud) c++ language-lawyer template-meta-programming user-defined-literals variadic-templates
当实现我自己的unique_ptr(只是为了好玩),我发现它无法通过这个测试文件来自libstdcxx:
struct A;
struct B
{
std::unique_ptr<A> a;
};
struct A
{
B* b;
~A() { VERIFY(b->a != nullptr); }
};
void test01()
{
B b;
b.a.reset(new A);
b.a->b = &b;
}
Run Code Online (Sandbox Code Playgroud)
gcc愉快地传递了这个测试文件(当然,这个文件是来自libstdcxx),而clang因为VERIFY部分失败了.
题:
b->a != nullptr)对于gcc很重要,否则它没有测试文件,但我不知道它背后是什么.它与优化有关吗?我知道很多UB都是为了更好的优化.9.1 C++
对于C++ ABI,我们将使用IA-64 C++ ABI并适当地实例化它.该ABI的当前草案可在以下网站获得:
为什么不设计自己的ABI?