Skip to content

Commit dfa1dd0

Browse files
committed
Added <algorithm> for max/min/clamp and fixed LLVM/Clang attributions
1 parent d3a69af commit dfa1dd0

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

src/libcxx/include/__config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
#pragma clang system_header
66

77
#define _EZCXX_INLINE [[__gnu__::__visibility__("hidden"), __gnu__::__always_inline__]] inline
8+
#define _EZCXX_NODISCARD [[nodiscard]]
9+
#define _EZCXX_NODISCARD_EXT [[nodiscard]]
810

911
#endif // _EZCXX_CONFIG

src/libcxx/include/algorithm

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _EZCXX_ALGORITHM
11+
#define _EZCXX_ALGORITHM
12+
13+
#include <__config>
14+
15+
// currently unused, but included in the standard
16+
#include <initializer_list>
17+
18+
#pragma clang system_header
19+
20+
// very limited implementation of <algorithm>
21+
// only supports std:max, std::min, and std::clamp
22+
// these functions can be replaced when <algorithm> is properly implemented
23+
24+
namespace std {
25+
26+
template <class _Tp, class _Compare> _EZCXX_NODISCARD_EXT inline constexpr
27+
const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp)
28+
{
29+
return __comp(__a, __b) ? __b : __a;
30+
}
31+
32+
template <class _Tp> _EZCXX_NODISCARD_EXT inline constexpr
33+
const _Tp& max(const _Tp& __a, const _Tp& __b)
34+
{
35+
return (__a < __b) ? __b : __a;
36+
}
37+
38+
template <class _Tp, class _Compare> _EZCXX_NODISCARD_EXT inline constexpr
39+
const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp)
40+
{
41+
return __comp(__a, __b) ? __a : __b;
42+
}
43+
44+
template <class _Tp> _EZCXX_NODISCARD_EXT inline constexpr
45+
const _Tp& min(const _Tp& __a, const _Tp& __b)
46+
{
47+
return (__a < __b) ? __a : __b;
48+
}
49+
50+
template <class _Tp, class _Compare> _EZCXX_NODISCARD_EXT inline constexpr
51+
const _Tp& clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
52+
{
53+
return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
54+
}
55+
56+
template <class _Tp> _EZCXX_NODISCARD_EXT inline constexpr
57+
const _Tp& clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
58+
{
59+
return (__v < __lo) ? __lo : (__hi < __v) ? __hi : __v;
60+
}
61+
62+
} // namespace std
63+
64+
#endif // _EZCXX_ALGORITHM

src/libcxx/include/numbers

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
210
#ifndef _EZCXX_NUMBERS
311
#define _EZCXX_NUMBERS
412

src/libcxx/include/version

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
210
#ifndef _EZCXX_VERSION
311
#define _EZCXX_VERSION
412

@@ -39,7 +47,7 @@
3947
// # define __cpp_lib_boyer_moore_searcher 201603L
4048
# define __cpp_lib_byte 201603L
4149
// # define __cpp_lib_chrono 201611L
42-
// # define __cpp_lib_clamp 201603L
50+
# define __cpp_lib_clamp 201603L
4351
// # define __cpp_lib_enable_shared_from_this 201603L
4452
// # define __cpp_lib_execution 201603L
4553
// # define __cpp_lib_filesystem 201703L

0 commit comments

Comments
 (0)