我正在编写允许对范围进行一些函数编程操作的库。范围是 STL 容器的泛化。我的问题是空范围折叠的结果应该是什么?
auto r = range(4); // lazy numeric range {0,1,2,3}
auto r0 = range(0); // empty range {}
vector<string> vs {"a", "bb"};
vector<string> vs0 {};
// this is obvious and implemented part
cout << (r || add); // 6, || - folding op
cout << (r0 || add); // 0
cout << (vs || add); // "abb"
cout << (vs0|| add); // ""
cout << (r || mul); // 0
cout << (r0 || mul); // 1
cout << (r || max); // 3
// What result of these should be?
cout << (r0 || div); // ???
cout << (r0 || sub); // ???
cout << (r0 || max); // -∞ ???
cout << (r0 || min); // +∞ ???
cout << (r0 || ???); // result of arbitrary op?
编辑 - 答案