aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/array_size.h
blob: 16ecc0364624d3408d8ba432eff81f6e2c2e7594 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once

#include <cstddef>

namespace NArraySizePrivate {
    template <class T>
    struct TArraySize;

    template <class T, size_t N>
    struct TArraySize<T[N]> {
        enum {
            Result = N
        };
    };

    template <class T, size_t N>
    struct TArraySize<T (&)[N]> {
        enum {
            Result = N
        };
    };
} // namespace NArraySizePrivate

#define Y_ARRAY_SIZE(arr) ((size_t)::NArraySizePrivate::TArraySize<decltype(arr)>::Result)