<commit_before>#ifndef FIXED_VECTOR_H__
#define FIXED_VECTOR_H__
#include <stdexcept>
#include <cstdlib>
#include <type_traits>
#include <memory>

#ifndef CONST_IF
#if __cplusplus >= 201703L
#define CONST_IF(...) if constexpr(__VA_ARGS__)
#else
#define CONST_IF(...) if(__VA_ARGS__)
#endif
#endif

namespace fixed {

template<typename T, size_t aln=0>
class vector {
    static_assert(std::is_trivially_destructible<T>::value, "T must not have a destructor to call");
    T *data_;
    size_t n_;
public:
    static T *allocate(size_t nelem) {
        T *ret;
        const size_t nb = nelem * sizeof(T);
        CONST_IF(aln) {
#if _GLIBCXX_HAVE_ALIGNED_ALLOC
            ret = std::aligned_alloc(aln, nb);
#else
            ret = nullptr;
            (void)posix_memalign((void **)&ret, aln, nb);
#endif
        } else {
            ret = static_cast<T *>(std::malloc(nb));
        }
        if(ret == nullptr) throw std::bad_alloc();
        return ret;
    }
    template<typename It>
    vector(It i1, It i2): data_(allocate(std::distance(i1, i2))), n_(std::distance(i1, i2)) {
        std::copy(i1, i2, data_);
    }
    vector(size_t n): data_(allocate(n)), n_(n) {<commit_msg>Can't trust gcc, rely on posix_memalign.<commit_after>#ifndef FIXED_VECTOR_H__
#define FIXED_VECTOR_H__
#include <stdexcept>
#include <cstdlib>
#include <type_traits>
#include <memory>

#ifndef CONST_IF
#if __cplusplus >= 201703L
#define CONST_IF(...) if constexpr(__VA_ARGS__)
#else
#define CONST_IF(...) if(__VA_ARGS__)
#endif
#endif

namespace fixed {

template<typename T, size_t aln=0>
class vector {
    static_assert(std::is_trivially_destructible<T>::value, "T must not have a destructor to call");
    T *data_;
    size_t n_;
public:
    static T *allocate(size_t nelem) {
        T *ret;
        const size_t nb = nelem * sizeof(T);
        CONST_IF(aln) {
            ret = nullptr;
            (void)posix_memalign((void **)&ret, aln, nb);
        } else {
            ret = static_cast<T *>(std::malloc(nb));
        }
        if(ret == nullptr) throw std::bad_alloc();
        return ret;
    }
    template<typename It>
    vector(It i1, It i2): data_(allocate(std::distance(i1, i2))), n_(std::distance(i1, i2)) {
        std::copy(i1, i2, data_);
    }
    vector(size_t n): data_(allocate(n)), n_(n) {
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.013026487190620929, 'mean_word_length': 3.2905027932960893, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '733018', 'n_tokens_mistral': 868, 'n_tokens_neox': 842, 'n_words': 200}