SAT Solver Template
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1/**
2* @author Tim Luchterhand
3* @date 26.11.24
4* @file concepts.hpp
5* @brief Contains various type traits and concepts.
6* @note If you are familiar with the c++ type system, you might find these things useful. If not, don't be scared,
7* you don't need to understand them
8*/
9
10#ifndef CONCEPTS_HPP
11#define CONCEPTS_HPP
12
13#include <ostream>
14#include <concepts>
15#include <ranges>
16
17
18/**
19 * @brief namespace containing various type traits. Prefer using the concepts.
20 */
21namespace sat::traits {
22
23 template<template<typename...> typename Template, typename T>
24 struct is_same_template : std::false_type {};
25
26 template<template<typename...> typename Template, typename... Args>
27 struct is_same_template<Template, Template<Args...>> : std::true_type {};
28
29 template<template<typename ...> typename Template, typename T>
30 constexpr inline bool is_same_template_v = is_same_template<Template, std::remove_cvref_t<T>>::value;
31
32 template<typename T>
33 struct is_scalar {
34 static constexpr bool value = std::is_integral_v<T> or std::is_floating_point_v<T>;
35 };
36
37 template<typename T>
38 inline constexpr bool is_scalar_v = is_scalar<T>::value;
39
40 template<typename ...>
41 struct always_false : std::false_type {};
42
43 template<typename ...Ts>
44 inline constexpr bool always_false_v = always_false<Ts...>::value;
45
46}
47
48/**
49 * @brief namespace containing various type concepts
50 */
51namespace sat::concepts {
52 /**
53 * Concept for a callable object that is invocable with various arguments and returns a certain return type
54 */
55 template<typename Functor, typename Return, typename ...Args>
56 concept callable_r = std::invocable<Functor, Args...> &&
58
59 /**
60 * Type that is either some integer or floating point type
61 */
62 template<typename T>
63 concept scalar = traits::is_scalar_v<T>;
64
65 /**
66 * C++20 range of a given type
67 */
68 template<typename R, typename T>
69 concept typed_range = std::ranges::range<R> && std::same_as<std::ranges::range_value_t<R>, T>;
70
71 /**
72 * C++20 range whose values can be converted to a certain type
73 */
74 template<typename R, typename T>
75 concept ctyped_range = std::ranges::range<R>and std::convertible_to<std::ranges::range_value_t<R>, T>;
76
77 /**
78 * C++20 range that contains some incomplete template type
79 */
80 template<typename R, template<typename> typename T>
81 concept ttyped_range = std::ranges::range<R> && traits::is_same_template_v<T, std::ranges::range_value_t<R>>;
82
83 /**
84 * Type that is of a given incomplete template type
85 */
86 template<typename T, template<typename...> typename Template>
87 concept same_template = traits::is_same_template_v<Template, T>;
88
89 /**
90 * Type that is an l-value reference to a given incomplete template type
91 */
92 template<typename T, template<typename...> typename Template>
93 concept same_template_lvref = same_template<T, Template> and std::is_lvalue_reference_v<T>;
94
95 /**
96 * Type that is a const l-value reference to a given incomplete template type
97 */
98 template<typename T, template<typename...> typename Template>
99 concept same_template_clvref = same_template_lvref<T, Template> and std::is_const_v<std::remove_reference_t<T>>;
100
101 /**
102 * Type that is an enum
103 */
104 template<typename T>
105 concept enum_type = std::is_enum_v<T>;
106}
107
108#endif //CONCEPTS_HPP
Clause class with watch literals.
Definition Clause.hpp:36
auto end() const -> std::vector< Literal >::const_iterator
Definition Clause.cpp:36
short getRank(Literal l) const
Definition Clause.cpp:20
Literal getWatcherByRank(short rank) const
Definition Clause.cpp:52
bool sameLiterals(const Clause &other) const
Definition Clause.cpp:56
bool setWatcher(Literal l, short watcherNo)
Definition Clause.cpp:28
Literal operator[](std::size_t index) const
Definition Clause.cpp:44
auto begin() const -> std::vector< Literal >::const_iterator
Definition Clause.cpp:32
std::size_t getIndex(short rank) const
Definition Clause.cpp:24
bool isEmpty() const
Definition Clause.cpp:40
std::size_t size() const
Definition Clause.cpp:48
Clause(std::vector< Literal > literals)
Definition Clause.cpp:16
Clause()=default
Structure representing a literal in a CNF-SAT problem.
Definition basic_structures.hpp:56
#define NOT_IMPLEMENTED
Definition exception.hpp:26
namespace containing various type concepts
Definition concepts.hpp:51
namespace containing various type traits. Prefer using the concepts.
Definition concepts.hpp:21
Definition basic_structures.cpp:10
Definition concepts.hpp:41
Definition concepts.hpp:24
Definition concepts.hpp:33