我发现自己刚刚写了这篇文章:
template <long int T_begin, long int T_end>
class range_class {
public:
class iterator {
friend class range_class;
public:
long int operator *() const { return i_; }
const iterator &operator ++() { ++i_; return *this; }
iterator operator ++(int) { iterator copy(*this); ++i_; return copy; }
bool operator ==(const iterator &other) const { return i_ == other.i_; }
bool operator !=(const iterator &other) const { return i_ != other.i_; }
protected:
iterator(long int start) : i_ (start) { } …Run Code Online (Sandbox Code Playgroud) 声明如下:
enum DrawBoldMode : unsigned
{
DBM_NONE = 0,
DBM_ITEM = 1<<0, // bold just the nearest line
DBM_SECTION = 1<<1, // bold all lines in the same section
DBM_LINETYPE = 1<<2, // bold all lines of the same line type
DBM_POINTAGE = 1<<3, // bold all lines of the same line type
};
Run Code Online (Sandbox Code Playgroud)
如何导出DrawBoldMode的基础类型(即无符号)?
我从一些算法书籍中读到了一个Queue的实现,有一个对我来说是新的/有趣的片段,我不明白.我认为它是像C++ 11中的向量初始化列表一样的新东西,但由于代码的上下文,我不是那么自信.任何人都可以光明或提供一些参考?
template <typename T>
class Queue {
private:
size_t head, tail, count;
vector<T> data;
public:
Queue(const size_t &cap=8) : head(0),tail(0),count(0),data({cap}) {}
//... more interfaces
//...
}
Run Code Online (Sandbox Code Playgroud)
可疑部分是数据({cap}),这是什么?它将矢量调整为容量上限?(显然,代码的作者打算在构造数据时给出数据大小.)
编辑:在阅读第一个答案和测试后,我们知道该书在代码段中有错误.它打算给出一个初始上限,但它使用了错误的{}.