chromium/third_party/angle/src/common/FixedVector.h

//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// FixedVector.h:
//   A vector class with a maximum size and fixed storage.
//

#ifndef COMMON_FIXEDVECTOR_H_
#define COMMON_FIXEDVECTOR_H_

#include "common/debug.h"

#include <algorithm>
#include <array>
#include <initializer_list>

namespace angle
{
template <class T, size_t N, class Storage = std::array<T, N>>
class FixedVector final
{
  public:
    using value_type             = typename Storage::value_type;
    using size_type              = typename Storage::size_type;
    using reference              = typename Storage::reference;
    using const_reference        = typename Storage::const_reference;
    using pointer                = typename Storage::pointer;
    using const_pointer          = typename Storage::const_pointer;
    using iterator               = typename Storage::iterator;
    using const_iterator         = typename Storage::const_iterator;
    using reverse_iterator       = typename Storage::reverse_iterator;
    using const_reverse_iterator = typename Storage::const_reverse_iterator;

    FixedVector();
    FixedVector(size_type count, const value_type &value);
    FixedVector(size_type count);

    FixedVector(const FixedVector<T, N, Storage> &other);
    FixedVector(FixedVector<T, N, Storage> &&other);
    FixedVector(std::initializer_list<value_type> init);

    FixedVector<T, N, Storage> &operator=(const FixedVector<T, N, Storage> &other);
    FixedVector<T, N, Storage> &operator=(FixedVector<T, N, Storage> &&other);
    FixedVector<T, N, Storage> &operator=(std::initializer_list<value_type> init);

    // Makes class trivially destructible.
    ~FixedVector() = default;

    reference at(size_type pos);
    const_reference at(size_type pos) const;

    reference operator[](size_type pos);
    const_reference operator[](size_type pos) const;

    pointer data();
    const_pointer data() const;

    iterator begin();
    const_iterator begin() const;

    iterator end();
    const_iterator end() const;

    bool empty() const;
    size_type size() const;
    static constexpr size_type max_size();

    void clear();

    void push_back(const value_type &value);
    void push_back(value_type &&value);

    template <class... Args>
    void emplace_back(Args &&...args);

    void pop_back();
    reference back();
    const_reference back() const;

    void swap(FixedVector<T, N, Storage> &other);

    void resize(size_type count);
    void resize(size_type count, const value_type &value);

    bool full() const;

  private:
    void assign_from_initializer_list(std::initializer_list<value_type> init);

    Storage mStorage;
    size_type mSize = 0;
};

template <class T, size_t N, class Storage>
bool operator==(const FixedVector<T, N, Storage> &a, const FixedVector<T, N, Storage> &b)
{}

template <class T, size_t N, class Storage>
bool operator!=(const FixedVector<T, N, Storage> &a, const FixedVector<T, N, Storage> &b)
{}

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage>::FixedVector() = default;

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage>::FixedVector(size_type count, const value_type &value) :{}

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage>::FixedVector(size_type count) :{}

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage>::FixedVector(const FixedVector<T, N, Storage> &other) = default;

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage>::FixedVector(FixedVector<T, N, Storage> &&other)
    :{}

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage>::FixedVector(std::initializer_list<value_type> init)
{}

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage> &FixedVector<T, N, Storage>::operator=(
    const FixedVector<T, N, Storage> &other) = default;

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage> &FixedVector<T, N, Storage>::operator=(
    FixedVector<T, N, Storage> &&other)
{}

template <class T, size_t N, class Storage>
FixedVector<T, N, Storage> &FixedVector<T, N, Storage>::operator=(
    std::initializer_list<value_type> init)
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::reference FixedVector<T, N, Storage>::at(size_type pos)
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::const_reference FixedVector<T, N, Storage>::at(
    size_type pos) const
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::reference FixedVector<T, N, Storage>::operator[](size_type pos)
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::const_reference FixedVector<T, N, Storage>::operator[](
    size_type pos) const
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::const_pointer angle::FixedVector<T, N, Storage>::data() const
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::pointer angle::FixedVector<T, N, Storage>::data()
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::iterator FixedVector<T, N, Storage>::begin()
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::const_iterator FixedVector<T, N, Storage>::begin() const
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::iterator FixedVector<T, N, Storage>::end()
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::const_iterator FixedVector<T, N, Storage>::end() const
{}

template <class T, size_t N, class Storage>
bool FixedVector<T, N, Storage>::empty() const
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::size_type FixedVector<T, N, Storage>::size() const
{}

template <class T, size_t N, class Storage>
constexpr typename FixedVector<T, N, Storage>::size_type FixedVector<T, N, Storage>::max_size()
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::clear()
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::push_back(const value_type &value)
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::push_back(value_type &&value)
{}

template <class T, size_t N, class Storage>
template <class... Args>
void FixedVector<T, N, Storage>::emplace_back(Args &&...args)
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::pop_back()
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::reference FixedVector<T, N, Storage>::back()
{}

template <class T, size_t N, class Storage>
typename FixedVector<T, N, Storage>::const_reference FixedVector<T, N, Storage>::back() const
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::swap(FixedVector<T, N, Storage> &other)
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::resize(size_type count)
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::resize(size_type count, const value_type &value)
{}

template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::assign_from_initializer_list(
    std::initializer_list<value_type> init)
{}

template <class T, size_t N, class Storage>
bool FixedVector<T, N, Storage>::full() const
{}
}  // namespace angle

#endif  // COMMON_FIXEDVECTOR_H_