-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathnumeric.cpp
35 lines (29 loc) · 971 Bytes
/
numeric.cpp
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
/*
* Copyright (c) 2022, Christopher Kormanyos
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------
#include <array>
#include <numeric>
#if (defined(__cpp_lib_constexpr_numeric) && (__cpp_lib_constexpr_numeric >= 201911L))
#define MODM_CONSTEXPR constexpr
#define MODM_CONSTEXPR_NUMERIC_IS_CONSTEXPR 1
#else
#define MODM_CONSTEXPR
#define MODM_CONSTEXPR_NUMERIC_IS_CONSTEXPR 0
#endif
MODM_CONSTEXPR std::array<int, 3U> a { 1, 2, 3 };
int main()
{
// 6
auto MODM_CONSTEXPR sum = std::accumulate(a.cbegin(), a.cend(), 0);
#if (MODM_CONSTEXPR_NUMERIC_IS_CONSTEXPR == 1)
static_assert(sum == 6, "Error: Unexpected std::accumulate result!");
#endif
return (sum == 6 ? 0 : -1);
}