GKD.RoboCtrl
RoboMaster Linux 电控:异步 IO、设备驱动与机器人控制
载入中...
搜索中...
未找到
concepts.hpp
浏览该文件的文档.
1
6#pragma once
7
8#include <type_traits>
9#include <utility>
10#include <cstddef>
11#include <stdexcept>
12
13namespace roboctrl::utils{
14
21template <typename F, typename Ret, typename... Args>
22concept invocable_r = std::is_invocable_r_v<Ret, F, Args...>;
23
24namespace detail {
25template <typename T, template <typename...> class S>
26struct instance_of_impl : std::false_type {};
27template <template <typename...> class S, typename... Args>
28struct instance_of_impl<S<Args...>, S> : std::true_type {};
29} // namespace detail
35template <typename T, template <typename...> class S>
36concept instance_of = detail::instance_of_impl<T, S>::value;
37
42template <typename T>
43concept immovable =
44 (not std::is_move_constructible_v<T>) and
45 (not std::is_move_assignable_v<T>);
46
51template <typename T>
52concept not_copyable =
53 (not std::is_copy_constructible_v<T>) and
54 (not std::is_copy_assignable_v<T>);
55
60 immovable_base() = default;
62 immovable_base& operator=(immovable_base&&) = delete;
63};
64
69 not_copyable_base() = default;
70 not_copyable_base(const not_copyable_base&) = delete;
71 not_copyable_base& operator=(const not_copyable_base&) = delete;
72};
73
77template<typename T>
78concept package = std::is_trivially_copyable_v<T>;
79
84template <typename T, typename U = T>
85struct pair {
86 std::pair<T, U> p;
87 T& first { p.first };
88 T& left { p.first };
89 U& second { p.second };
90 U& right { p.second };
91
92 pair() = default;
93
94 template <typename... Args>
95 requires (sizeof...(Args) > 0 && std::is_constructible_v<std::pair<T, U>, Args...>)
96 explicit pair(Args&&... args)
97 : p { std::forward<Args>(args)... }
98 {}
99
100 pair(const pair& other)
101 : p { other.p }, first { p.first }, left { p.first }, second { p.second }, right { p.second }
102 {}
103
104 pair(pair&& other) noexcept(std::is_nothrow_move_constructible_v<std::pair<T, U>>)
105 : p { std::move(other.p) }, first { p.first }, left { p.first }, second { p.second }, right { p.second }
106 {}
107
108 pair& operator=(const pair& other) {
109 p = other.p;
110 return *this;
111 }
112
113 pair& operator=(pair&& other) noexcept(std::is_nothrow_move_assignable_v<std::pair<T, U>>) {
114 p = std::move(other.p);
115 return *this;
116 }
117
118 operator std::pair<T, U>& () { return p; }
119 operator const std::pair<T, U>& () const { return p; }
120};
121
125namespace byte_literals {
131consteval std::byte operator""_b(unsigned long long int byte) {
132 if (byte > 0xff) throw std::out_of_range{ "std::byte literal exceeds 0xff." };
133 return static_cast<std::byte>(byte);
134}
135} // namespace byte_literals
136}
判断类型不可移动。
Definition concepts.hpp:43
判断类型是否为某模板的实例。
Definition concepts.hpp:36
约束可调用对象的返回值。
Definition concepts.hpp:22
判断类型不可复制。
Definition concepts.hpp:52
用于约束“可安全作为报文搬运”的平凡类型。
Definition concepts.hpp:78
用于存放工具函数的命名空间。
Definition ballistics.hpp:6
快速继承获得“不可移动”约束的基类。
Definition concepts.hpp:59
快速继承获得“不可复制”约束的基类。
Definition concepts.hpp:68
双值绑定结构,兼容 std::pair。
Definition concepts.hpp:85