array.h 1.08 KB
Newer Older
杉下大河's avatar
杉下大河 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

//ArduinoSTL.hには衝突回避のためにarryが無く、SPRESENSE側はイテレーターが使えないので手動実装

template <class T, size_t N>
struct inoArray {
    // Storage
    T data[N];

    static size_t length() { return N; }
    using type = T;

    // Item access
    T &operator[](size_t index) { return data[index]; }
    const T &operator[](size_t index) const { return data[index]; }

    // Iterators
    T *begin() { return &data[0]; }
    const T *begin() const { return &data[0]; }
    T *end() { return &data[N]; }
    const T *end() const { return &data[N]; }

    // Comparisons
    bool operator==(const inoArray<T, N> &rhs) const {
        if (this == &rhs)
            return true;
        for (size_t i = 0; i < N; i++)
            if ((*this)[i] != rhs[i])
                return false;
        return true;
    }
    bool operator!=(const inoArray<T, N> &rhs) const {
        return !(*this == rhs);
    }

    //Function
    
    void fill( const T& value )
    {
        for (size_t i=0;i<N ;i++) {
            data[i] = value;
        }
    }

    
};