summaryrefslogtreecommitdiffstats
path: root/src/common/concepts.h
blob: e8ce30dfedebdd897d1b29c93ed1ca1c8695062d (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <type_traits>

namespace Common {

// Check if type is like an STL container
template <typename T>
concept IsSTLContainer = requires(T t) {
    typename T::value_type;
    typename T::iterator;
    typename T::const_iterator;
    // TODO(ogniK): Replace below is std::same_as<void> when MSVC supports it.
    t.begin();
    t.end();
    t.cbegin();
    t.cend();
    t.data();
    t.size();
};

// TODO: Replace with std::derived_from when the <concepts> header
//       is available on all supported platforms.
template <typename Derived, typename Base>
concept DerivedFrom = requires {
    std::is_base_of_v<Base, Derived>;
    std::is_convertible_v<const volatile Derived*, const volatile Base*>;
};

// TODO: Replace with std::convertible_to when libc++ implements it.
template <typename From, typename To>
concept ConvertibleTo = std::is_convertible_v<From, To>;

// No equivalents in the stdlib

template <typename T>
concept IsArithmetic = std::is_arithmetic_v<T>;

template <typename T>
concept IsIntegral = std::is_integral_v<T>;

} // namespace Common