我无法理解之间的差异std::string
和std::wstring
.我知道wstring
支持Unicode字符等宽字符.我有以下问题:
std::wstring
用完std::string
?std::string
保存整个ASCII字符集,包括特殊字符吗?std::wstring
由所有流行的C++编译器的支持?对于许多问题,答案似乎可以在"标准"中找到.但是,我们在哪里找到它?最好是在线.
谷歌搜索有时会觉得徒劳,尤其是对于C标准,因为他们在编程论坛的大量讨论中被淹没.
要开始这个,因为这些是我现在正在搜索的,那里有很好的在线资源:
在clang的C++ 11状态页面中遇到了一个名为"rvalue reference for*this"的提案.
我已经阅读了很多关于rvalue引用并理解它们的内容,但我认为我不知道这一点.我也无法使用这些条款在网上找到太多资源.
页面上的提案文件有一个链接:N2439(将移动语义扩展到*this),但我也没有从中获得太多的例子.
这个功能是什么?
我有一个输入电子邮件的表单和两个提交按钮来订阅和取消订阅时事通讯:
<form action="" method="post">
{{ form_newsletter }}
<input type="submit" name="newsletter_sub" value="Subscribe" />
<input type="submit" name="newsletter_unsub" value="Unsubscribe" />
</form>
Run Code Online (Sandbox Code Playgroud)
我也有课堂形式:
class NewsletterForm(forms.ModelForm):
class Meta:
model = Newsletter
fields = ('email',)
Run Code Online (Sandbox Code Playgroud)
我必须编写自己的clean_email方法,我需要知道哪个按钮是提交的形式.但提交按钮的值不在self.cleaned_data
字典中.我能获得按钮的值吗?
我想知道C++完整概念提议和模板约束之间的语义差异(例如,Dlang中出现的约束或C++ 1y的新概念 - 精简提议).
什么是能够比模板约束做的完整概念不能做到的?
我想做这样的事情:
#include <iostream>
#include <random>
typedef int Integer;
#if sizeof(Integer) <= 4
typedef std::mt19937 Engine;
#else
typedef std::mt19937_64 Engine;
#endif
int main()
{
std::cout << sizeof(Integer) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
error: missing binary operator before token "("
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确地创建条件typedef?
在C++ 11中,我将如何编写一个采用已知类型但未知大小的std ::数组的函数(或方法)?
// made up example
void mulArray(std::array<int, ?>& arr, const int multiplier) {
for(auto& e : arr) {
e *= multiplier;
}
}
// lets imagine these being full of numbers
std::array<int, 17> arr1;
std::array<int, 6> arr2;
std::array<int, 95> arr3;
mulArray(arr1, 3);
mulArray(arr2, 5);
mulArray(arr3, 2);
Run Code Online (Sandbox Code Playgroud)
在我的搜索过程中,我只找到了使用模板的建议,但这些看起来很混乱(标题中的方法定义),而且我想要完成的内容过多.
是否有一种简单的方法可以实现这一点,就像普通的C风格数组一样?
我想更好地了解为什么选择int
结束unsigned
?
就个人而言,除非有正当理由,否则我从未喜欢过签名的价值观.例如,数组中的项目数,或字符串的长度,或内存块的大小等,因此这些事情通常不可能是负面的.这样的价值没有任何意义.为什么喜欢int
在所有这些情况下误导?
我问这个问题是因为Bjarne Stroustrup和Chandler Carruth都给出了建议,而int
不是unsigned
在这里(约12:30').
我可以看到使用int
over short
或long
- 的参数int
是目标机器架构的"最自然"的数据宽度.
但签署无条件总是让我生气.在典型的现代CPU架构上,签名值是否真的更快?是什么让他们更好?
我正在尝试使用Concepts Lite来指定一个概念来约束具有成员函数模板的更高级的kinded类型.但是,我无法在技术规范或教程中找到一个处理概念中模板化语句的子句.
这是怎么做到的?
示例:假设我HKT
的成员函数模板具有更高的kinded类型F
:
template<class T>
struct HKT {
template<class U> // this looks like e.g. rebind in std::allocators
auto F(U) -> HKT<U>;
};
Run Code Online (Sandbox Code Playgroud)
现在我想指定一个约束这些更高级的类型的概念:
template <template <class> class HKT, class T>
concept HKTWithTemplateMemberFunctionF {
return requires(HKT<T> h) { // HKT<T> is a type, h is an object
// HKT<T> needs to have a member function template that
// returns HTK<U> where the type U is to be deduced and
// it …
Run Code Online (Sandbox Code Playgroud) 考虑一下这个C++ 11代码片段:
#include <iostream>
#include <set>
#include <stdexcept>
#include <initializer_list>
int main(int argc, char ** argv)
{
enum Switch {
Switch_1,
Switch_2,
Switch_3,
Switch_XXXX,
};
int foo_1 = 1;
int foo_2 = 2;
int foo_3 = 3;
int foo_4 = 4;
int foo_5 = 5;
int foo_6 = 6;
int foo_7 = 7;
auto get_foos = [=] (Switch ss) -> std::initializer_list<int> {
switch (ss) {
case Switch_1:
return {foo_1, foo_2, foo_3};
case Switch_2:
return {foo_4, foo_5};
case Switch_3: …
Run Code Online (Sandbox Code Playgroud) c++ ×9
c++11 ×5
c++-faq ×3
c++-concepts ×2
button ×1
c ×1
d ×1
django-forms ×1
lambda ×1
optimization ×1
python ×1
qualifiers ×1
standards ×1
stdarray ×1
string ×1
submit ×1
unicode ×1
wstring ×1