using namespace std::rel_ops;
template <typename T, typename A = std::allocator<T> >
class my_vector {
public:
typedef A allocator_type;
typedef typename allocator_type::value_type value_type;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::pointer iterator;
typedef typename allocator_type::const_pointer const_iterator;
public:
friend bool operator == (const my_vector& lhs, const my_vector& rhs) {
return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin());}
friend bool operator < (const my_vector& lhs, const my_vector& rhs) {
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());}
friend void swap (my_vector& x, my_vector& y) {
x.swap(y);}
private:
allocator_type _a;
pointer _b;
pointer _e; // size
pointer _l; // capacity
private:
bool valid () const {
return (!_b && !_e && !_l) || ((_b <= _e) && (_e <= _l));}
my_vector (const my_vector& that, size_type c) :
_a (that._a) {
assert(c >= that.size());
_b = _a.allocate(c);
_e = _b + that.size();
_l = _b + c;
my_uninitialized_copy(_a, that.begin(), that.end(), begin());
assert(valid());}
私はこのコードのスニペットを調べていましたが、C++ は初めてなので、理解できないことがたくさんあります。
- "
bool valid () const
" のこの行 " " は何を(!_b && !_e && !_l)
しようとしていますか?
それはポインターを否定しています。私はそれが何をしているのか、何を達成しようとしているのかわかりません。
「 」の行で、「 」
my_vector (const my_vector& that, size_type c) :
の型は何that
ですか? 独自のクラスへの参照ですか?"
my_vector (const my_vector& that, size_type c) :
" で、この行 " " は何をしているの_a (that._a) :
ですか? '_a
' は Allocator オブジェクトですか? この行の下に "_a.allocate(c),
" があり、'allocate' は Allocator のメンバ関数であるためです。const_pointer とポインタの両方を持つ目的は何ですか? また、reference と const_reference の両方、および iterator と const_iterator の両方ですか? クラス my_vector の下の最初のパブリックで?