<commit_before>#ifndef FLEX_FIXED_VECTOR_H
#define FLEX_FIXED_VECTOR_H

#include <flex/vector.h>

namespace flex
{

   //TODO: Put this in the proper place.  Maybe fixed pool.
   template<size_t N>
   struct aligned_buffer
   {
      char mBuffer[N];
   };
   
  template<class T, size_t N, class Alloc = allocator<T> > class fixed_vector: public vector<T, Alloc>
  {
  public:
    typedef vector<T, Alloc> base_type;

    typedef typename base_type::value_type value_type;
    typedef typename base_type::pointer pointer;
    typedef typename base_type::const_pointer const_pointer;
    typedef typename base_type::reference reference;
    typedef typename base_type::const_reference const_reference;
    typedef typename base_type::iterator iterator;
    typedef typename base_type::const_iterator const_iterator;
    typedef typename base_type::reverse_iterator reverse_iterator;
    typedef typename base_type::const_reverse_iterator const_reverse_iterator;
    typedef typename base_type::size_type size_type;
    typedef typename base_type::difference_type difference_type;

    using base_type::mBegin;
    using base_type::mEnd;
    using base_type::mCapacity;
    using base_type::assign;

    fixed_vector();
    explicit fixed_vector(size_type size, const value_type& val = value_type());
    fixed_vector(int size, const value_type& val);
    template<typename InputIterator> fixed_vector(InputIterator first, InputIterator last);
    fixed_vector(const fixed_vector<T, N, Alloc> & obj);
    fixed_vector(const vector<T, Alloc> & obj);

    fixed_vector<T, N, Alloc>& operator=(const fixed_vector<T, N, Alloc>& obj);
    fixed_vector<T, N, Alloc>& operator=(const vector<T, Alloc>& obj);
    size_type max_size() const;

  private:
    aligned_buffer<N * sizeof(T)> mBuffer;
  };

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector() :
      vector<T, Alloc>((pointer)(&mBuffer), (pointer)(&mBuffer), N)
  {
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(size_type size, const value_type& val) :
      vector<T, Alloc>((pointer)(&mBuffer), (pointer)(&mBuffer) + size, N)
  {
    std::fill(mBegin, mEnd, val);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(int size, const value_type& val) :
      vector<T, Alloc>((pointer)(&mBuffer), (pointer)(&mBuffer) + size, N)
  {
    std::fill(mBegin, mEnd, val);
  }

  template<class T, size_t N, class Alloc>
  template<typename InputIterator>
  inline fixed_vector<T, N, Alloc>::fixed_vector(InputIterator first, InputIterator last) :
      vector<T, Alloc>((pointer)(&mBuffer), (pointer)(&mBuffer) + std::distance(first, last), N)
  {
    std::copy(first, last, mBegin);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(const fixed_vector<T, N, Alloc> & obj) :
      vector<T, Alloc>((pointer)(&mBuffer), (pointer)(&mBuffer) + std::distance(obj.mBegin, obj.mEnd), N)
  {
    std::copy(obj.mBegin, obj.mEnd, mBegin);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(const vector<T, Alloc> & obj) :
      vector<T, Alloc>((pointer)(&mBuffer), (pointer)(&mBuffer) + std::distance(obj.mBegin, obj.mEnd), N)
  {
    std::copy(obj.mBegin, obj.mEnd, mBegin);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>& fixed_vector<T, N, Alloc>::operator=(const fixed_vector<T, N, Alloc>& obj)
  {
    //A bit more efficient than assign() as no capacity check is needed.
    std::copy(obj.mBegin, obj.mEnd, mBegin);
    mEnd = mBegin + obj.size();
    return *this;
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>& fixed_vector<T, N, Alloc>::operator=(const vector<T, Alloc>& obj)
  {
    assign(obj.begin(), obj.end());
    return *this;
  }

  template<class T, size_t N, class Alloc>
  inline typename fixed_vector<T, N, Alloc>::size_type fixed_vector<T, N, Alloc>::max_size() const
  {
    return N;
  }

} //namespace flex

#endif /* FLEX_FIXED_VECTOR_H */
<commit_msg>Didn't do much but read.<commit_after>#ifndef FLEX_FIXED_VECTOR_H
#define FLEX_FIXED_VECTOR_H

#include <stdint.h>
#include <flex/vector.h>

namespace flex
{

  template<class T, size_t N, class Alloc = allocator<T> > class fixed_vector: public vector<T, Alloc>
  {
  public:
    typedef vector<T, Alloc> base_type;

    typedef typename base_type::value_type value_type;
    typedef typename base_type::pointer pointer;
    typedef typename base_type::const_pointer const_pointer;
    typedef typename base_type::reference reference;
    typedef typename base_type::const_reference const_reference;
    typedef typename base_type::iterator iterator;
    typedef typename base_type::const_iterator const_iterator;
    typedef typename base_type::reverse_iterator reverse_iterator;
    typedef typename base_type::const_reverse_iterator const_reverse_iterator;
    typedef typename base_type::size_type size_type;
    typedef typename base_type::difference_type difference_type;

    using base_type::mBegin;
    using base_type::mEnd;
    using base_type::mCapacity;
    using base_type::assign;

    fixed_vector();
    explicit fixed_vector(size_type size, const value_type& val = value_type());
    fixed_vector(int size, const value_type& val);
    template<typename InputIterator> fixed_vector(InputIterator first, InputIterator last);
    fixed_vector(const fixed_vector<T, N, Alloc> & obj);
    fixed_vector(const vector<T, Alloc> & obj);

    fixed_vector<T, N, Alloc>& operator=(const fixed_vector<T, N, Alloc>& obj);
    fixed_vector<T, N, Alloc>& operator=(const vector<T, Alloc>& obj);
    size_type max_size() const;

  private:
    //This union is the simplest approach to enforce alignment prior to C++11.
    //If C++11 support is added, replace with:
    //typename std::aligned_storage<sizeof(T), alignof(T)>::type mBuffer[N];
    union
    {
      char mBuffer[N * sizeof(T)];
      uint64_t dummy;
    };
  };

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector() :
      vector<T, Alloc>((pointer)mBuffer, (pointer)mBuffer, N)
  {
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(size_type size, const value_type& val) :
      vector<T, Alloc>((pointer) mBuffer, (pointer) mBuffer + size, N)
  {
    std::fill(mBegin, mEnd, val);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(int size, const value_type& val) :
      vector<T, Alloc>((pointer) mBuffer, (pointer) mBuffer + size, N)
  {
    std::fill(mBegin, mEnd, val);
  }

  template<class T, size_t N, class Alloc>
  template<typename InputIterator>
  inline fixed_vector<T, N, Alloc>::fixed_vector(InputIterator first, InputIterator last) :
      vector<T, Alloc>((pointer) mBuffer, (pointer) mBuffer + std::distance(first, last), N)
  {
    std::copy(first, last, mBegin);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(const fixed_vector<T, N, Alloc> & obj) :
      vector<T, Alloc>((pointer) mBuffer, (pointer) mBuffer + std::distance(obj.mBegin, obj.mEnd), N)
  {
    std::copy(obj.mBegin, obj.mEnd, mBegin);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>::fixed_vector(const vector<T, Alloc> & obj) :
      vector<T, Alloc>((pointer) mBuffer, (pointer) mBuffer + std::distance(obj.mBegin, obj.mEnd), N)
  {
    std::copy(obj.mBegin, obj.mEnd, mBegin);
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>& fixed_vector<T, N, Alloc>::operator=(const fixed_vector<T, N, Alloc>& obj)
  {
    //A bit more efficient than assign() as no capacity check is needed.
    std::copy(obj.mBegin, obj.mEnd, mBegin);
    mEnd = mBegin + obj.size();
    return *this;
  }

  template<class T, size_t N, class Alloc>
  inline fixed_vector<T, N, Alloc>& fixed_vector<T, N, Alloc>::operator=(const vector<T, Alloc>& obj)
  {
    assign(obj.begin(), obj.end());
    return *this;
  }

  template<class T, size_t N, class Alloc>
  inline typename fixed_vector<T, N, Alloc>::size_type fixed_vector<T, N, Alloc>::max_size() const
  {
    return N;
  }

} //namespace flex

#endif /* FLEX_FIXED_VECTOR_H */

{'fraction_non_alphanumeric': 0.12925659472422063, 'fraction_numerical': 0.0007194244604316547, 'mean_word_length': 4.509247027741083, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4002514', 'n_tokens_mistral': 2896, 'n_tokens_neox': 2834, 'n_words': 722}