gw  1.0.0
A bunch of small C++ utilities
Loading...
Searching...
No Matches
concepts.hpp
1// Copyright (c) 2023 Martin Stump
2// SPDX-License-Identifier: BSL-1.0
3
4#pragma once
5
6#include <concepts>
7#include <cstddef>
8#include <functional>
9#include <iostream>
10#include <string>
11#include <type_traits>
12
14namespace gw {
15
17template <typename T>
18concept arithmetic = requires { std::is_arithmetic_v<T>; };
19
21template <typename T>
22concept incrementable = requires(T value) {
23 { ++value } -> std::common_with<T>;
24 value++;
25};
26
28template <typename T>
29concept decrementable = requires(T value) {
30 { --value } -> std::common_with<T>;
31 value--;
32};
33
35template <typename T>
36concept complete = requires { sizeof(T); };
37
39template <typename T>
40concept hashable = requires(T value) {
41 { std::hash<T>{}(value) } -> std::same_as<std::size_t>;
42};
43
45template <typename T>
46concept ostreamable = requires(std::ostream& ostream, T value) {
47 { ostream << value } -> std::same_as<std::ostream&>;
48};
49
51template <typename T>
52concept istreamable = requires(std::istream& istream, T value) {
53 { istream >> value } -> std::same_as<std::istream&>;
54};
55
57template <typename T>
58concept named = requires(T value) {
59 { value.name() } -> std::convertible_to<std::string>;
60};
61
62} // namespace gw
Concept for arithmetic types.
Definition concepts.hpp:18
Concept for complete types.
Definition concepts.hpp:36
Concept for decrementable types.
Definition concepts.hpp:29
Concept for hashable types.
Definition concepts.hpp:40
Concept for incrementable types.
Definition concepts.hpp:22
Concept for istreamable types.
Definition concepts.hpp:52
Concept for named types.
Definition concepts.hpp:58
Concept for ostreamable types.
Definition concepts.hpp:46
GW namespace.
Definition concepts.hpp:14