// Copyright 2018 The RE2 Authors. All Rights Reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. #ifndef RE2_POD_ARRAY_H_ #define RE2_POD_ARRAY_H_ #include #include namespace re2 { template class PODArray { public: static_assert(std::is_trivial::value && std::is_standard_layout::value, "T must be POD"); PODArray() : ptr_() {} explicit PODArray(int len) : ptr_(std::allocator().allocate(len), Deleter(len)) {} T* data() const { return ptr_.get(); } int size() const { return ptr_.get_deleter().len_; } T& operator[](int pos) const { return ptr_[pos]; } private: struct Deleter { Deleter() : len_(0) {} explicit Deleter(int len) : len_(len) {} void operator()(T* ptr) const { std::allocator().deallocate(ptr, len_); } int len_; }; std::unique_ptr ptr_; }; } // namespace re2 #endif // RE2_POD_ARRAY_H_