我找到了一个不起眼的日志记录错误,事实上长度为2的初始化列表似乎是一个特例!这怎么可能?
代码是使用Apple LLVM版本5.1(clang-503.0.40)编译的CXXFLAGS=-std=c++11 -stdlib=libc++
.
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef vector<string> Strings;
void print(string const& s) {
printf(s.c_str());
printf("\n");
}
void print(Strings const& ss, string const& name) {
print("Test " + name);
print("Number of strings: " + to_string(ss.size()));
for (auto& s: ss) {
auto t = "length = " + to_string(s.size()) + ": " + s;
print(t);
}
print("\n");
}
void test() {
Strings a{{"hello"}}; print(a, "a");
Strings b{{"hello", "there"}}; print(b, "b");
Strings c{{"hello", …
Run Code Online (Sandbox Code Playgroud)