std :: shared_ptr构造函数的行为不符合我的预期:
#include <iostream>
#include <vector>
void func(std::vector<std::string> strings)
{
for (auto const& string : strings)
{
std::cout << string << '\n';
}
}
struct Func
{
Func(std::vector<std::string> strings)
{
for (auto& string : strings)
{
std::cout << string << '\n';
}
}
};
int main(int argc, const char * argv[])
{
func({"foo", "bar", "baz"});
Func({"foo", "bar", "baz"});
//auto ptr = std::make_shared<Func>({"foo", "bar", "baz"}); // won't compile.
//auto ptr = std::make_shared<Func>{"foo", "bar", "baz"}; // nor this.
return 0;
} …Run Code Online (Sandbox Code Playgroud) 代替:
$ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
我想,例如:
$ python --quiet
>>>
Run Code Online (Sandbox Code Playgroud) 我尽可能地缩小了它,这似乎是一个错误......
#include <algorithm>
#include <vector>
int main(int argc, char *argv[])
{
// Crashes
std::vector<uint8_t> bs{1, 0, 0};
std::search_n(bs.begin(), bs.end(), 3, 1);
// Does not crash
std::vector<uint8_t> bs{1, 0};
std::search_n(bs.begin(), bs.end(), 2, 1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我明白了
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)
我希望我没有错误地使用std :: search_n :)
目前使用LLDB似乎无法单步执行STL实现.
版本信息:
$clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)
证据;)
13:06:47 ~/bug$ cat bug.cc
#include <algorithm>
#include <vector>
int main(int argc, char *argv[])
{
std::vector<uint8_t> bs{1, 0, 0}; …Run Code Online (Sandbox Code Playgroud) 我有一个函数,需要一对迭代器.我想提供一个函数的无参数版本,其行为就像传递了一个空范围一样.
具体来说,让我们说第一个功能是:
void f(vector<int>::iterator b, vector<int>::iterator e) { // impl. }
Run Code Online (Sandbox Code Playgroud)
我想写这个:
void f() { f({}, {}); }
Run Code Online (Sandbox Code Playgroud)
我在这里初始化是否正确,{},{}应该是两个默认构造的vector :: iterator类型?(它汇编).
我是否必须构造一个容器来获得一对比较相等的迭代器?
这里:
http://en.cppreference.com/w/cpp/utility/functional/function
operator bool 描述:"检查存储的可调用对象是否有效".
据推测,默认构造std::function无效,但这是唯一的情况吗?
另外,它如何检查它是否有效?
是否恰好operator()引发std::bad_function_call了对象无效的情况?
我正在解析一个文本文件,可能有几GB大小,由以下行组成:
11 0.1
14 0.78
532 -3.5
Run Code Online (Sandbox Code Playgroud)
基本上,每行一个int和一个float.整数应该是有序的而且是非负的.我想验证数据是否如描述,并返回给我范围内的最小和最大int.这就是我想出来的:
#include <iostream>
#include <string>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/std_pair.hpp>
namespace px = boost::phoenix;
namespace qi = boost::spirit::qi;
namespace my_parsers
{
using namespace qi;
using px::at_c;
using px::val;
template <typename Iterator>
struct verify_data : grammar<Iterator, locals<int>, std::pair<int, int>()>
{
verify_data() : verify_data::base_type(section)
{
section
= line(val(0)) [ at_c<0>(_val) = _1]
>> +line(_a) [ _a = _1]
>> eps [ at_c<1>(_val) = _a]
;
line
%= (int_ >> other) [
if_(_r1 >= _1) …Run Code Online (Sandbox Code Playgroud) 我希望它会打破其他一些解析,但这并不会立即浮出水面......
例如,如果我这样说:
#include <stdio.h>
int main()
{
int i = 10 000;
printf("%d\n", i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的编译器说:
ctest.c:5: error: expected ‘,’ or ‘;’ before numeric constant
Run Code Online (Sandbox Code Playgroud)
我认为它将是一个特征,即用数千个分隔符"眼睛解析"大整数更容易.我正在使用最近的GCC并假设其他编译器/解析器/词法分析器就是这种情况; 无论哪个是物体.
c++ ×5
c++11 ×4
stl ×2
boost ×1
boost-spirit ×1
c ×1
clang ×1
libc++ ×1
python ×1
shared-ptr ×1
std-function ×1