repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
concepts.h
Go to the documentation of this file.
1#pragma once
2#include <concepts>
3#include <type_traits>
4#include <string>
5
6namespace librepr::detail {
7template <typename T>
8concept pair_like = requires(T t) {
9 t.first;
10 t.second;
11 requires std::is_same_v<typename T::first_type, decltype(t.first)>;
12 requires std::is_same_v<typename T::second_type, decltype(t.second)>;
13};
14
15template <typename T>
16concept has_repr_member = requires(T const& obj) {
17 { obj.repr() } -> std::same_as<std::string>;
18};
19
20template <typename T>
21concept is_scoped_enum = !std::is_convertible_v<T, std::underlying_type_t<T>>;
22
23template <typename T, std::size_t N>
24concept is_tuple_element = requires(T t) {
25 typename std::tuple_element_t<N, std::remove_const_t<T>>;
26 { get<N>(t) } -> std::convertible_to<std::tuple_element_t<N, T> const&>;
27};
28template <typename T>
29concept tuple_like = !std::is_reference_v<T> && requires {
30 typename std::tuple_size<T>::type;
31 requires std::same_as<decltype(std::tuple_size_v<T>), size_t>;
32} && []<std::size_t... I>(std::index_sequence<I...>) {
33 return (is_tuple_element<T, I> && ...);
35
36} // namespace librepr::detail
Definition concepts.h:16
Definition concepts.h:21
Definition concepts.h:24
Definition concepts.h:8
Definition concepts.h:29
T is_same_v
Definition assert.h:89
std::string code_for()
Definition repr:39