Sha256: 19bbffc561f105f05b82541769930a7146cdb3b07c7100fa9bde2e3321649273

Contents?: true

Size: 1.03 KB

Versions: 99

Compression:

Stored size: 1.03 KB

Contents

// 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 <memory>
#include <type_traits>

namespace re2 {

template <typename T>
class PODArray {
 public:
  static_assert(std::is_trivial<T>::value && std::is_standard_layout<T>::value,
                "T must be POD");

  PODArray()
      : ptr_() {}
  explicit PODArray(int len)
      : ptr_(std::allocator<T>().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<T>().deallocate(ptr, len_);
    }

    int len_;
  };

  std::unique_ptr<T[], Deleter> ptr_;
};

}  // namespace re2

#endif  // RE2_POD_ARRAY_H_

Version data entries

99 entries across 99 versions & 3 rubygems

Version Path
grpc-1.69.0 third_party/re2/re2/pod_array.h
grpc-1.69.0.pre1 third_party/re2/re2/pod_array.h
grpc-1.68.1 third_party/re2/re2/pod_array.h
grpc-1.67.0 third_party/re2/re2/pod_array.h
grpc-1.67.0.pre1 third_party/re2/re2/pod_array.h
grpc-1.66.0 third_party/re2/re2/pod_array.h
grpc-1.66.0.pre5 third_party/re2/re2/pod_array.h
grpc-1.66.0.pre3 third_party/re2/re2/pod_array.h
grpc-1.58.3 third_party/re2/re2/pod_array.h
grpc-1.59.5 third_party/re2/re2/pod_array.h
grpc-1.60.2 third_party/re2/re2/pod_array.h
grpc-1.61.3 third_party/re2/re2/pod_array.h
grpc-1.62.3 third_party/re2/re2/pod_array.h
grpc-1.63.2 third_party/re2/re2/pod_array.h
grpc-1.64.3 third_party/re2/re2/pod_array.h
grpc-1.65.2 third_party/re2/re2/pod_array.h
grpc-1.65.1 third_party/re2/re2/pod_array.h
grpc-1.65.0 third_party/re2/re2/pod_array.h
grpc-1.65.0.pre2 third_party/re2/re2/pod_array.h
grpc-1.65.0.pre1 third_party/re2/re2/pod_array.h