Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
concepts.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file compat/concepts.hh
4 *
5 * @brief Provides backports of some `concepts` features that are missing in
6 * Clang v11.
7 *
8 *
9 * -------------------------------------------------------------------------- */
10
11#pragma once
12
13#include <concepts> // IWYU pragma: export
14
15
16/* -------------------------------------------------------------------------- */
17
18/* Only provide these definitions for older versions of Clang. */
19#if defined( __clang__ ) && ( __clang_major__ < 15 )
20
21/* -------------------------------------------------------------------------- */
22
23/* Yeah, I know: "iT's IlLeGaL tO eXtEnD `std::*'".
24 * This backports definitions exactly as written, so it's fine. */
25namespace std {
26
27/* -------------------------------------------------------------------------- */
28
34template<class T>
35concept destructible = std::is_nothrow_destructible_v<T>;
36
37
38/* -------------------------------------------------------------------------- */
39
44template<class T, class... Args>
45concept constructible_from
46 = std::destructible<T> && std::is_constructible_v<T, Args...>;
47
48
49/* -------------------------------------------------------------------------- */
50
57template<class From, class To>
58concept convertible_to = std::is_convertible_v<From, To> && requires {
59 static_cast<To>( std::declval<From>() );
60};
61
62
63/* -------------------------------------------------------------------------- */
64
72template<class Derived, class Base>
73concept derived_from
74 = std::is_base_of_v<Base, Derived>
75 && std::is_convertible_v<const volatile Derived *, const volatile Base *>;
76
77
78/* -------------------------------------------------------------------------- */
79
80} // namespace std
81
82
83/* -------------------------------------------------------------------------- */
84
85#endif // defined( __clang__ ) && ( __clang_major__ < 15 )
86
87
88/* -------------------------------------------------------------------------- *
89 *
90 *
91 *
92 * ========================================================================== */