Skip to content

Commit 38fc1cd

Browse files
authored
Add synopsis for components (#2)
Add the standards synopsis for the components for reference Add bad_expected_access component Add codespell override for `unexpect` in pyproject.toml TODO: Add codespell file
2 parents d10aba3 + 7212645 commit 38fc1cd

File tree

9 files changed

+379
-20
lines changed

9 files changed

+379
-20
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ updates:
3131
directory: /
3232
schedule:
3333
interval: daily
34-

.pre-commit-config.yaml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,42 @@ repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v6.0.0
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
- id: check-added-large-files
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
1111

12-
# Clang-format for C++
13-
# This brings in a portable version of clang-format.
14-
# See also: https://github.com/ssciwr/clang-format-wheel
12+
# Clang-format for C++
13+
# This brings in a portable version of clang-format.
14+
# See also: https://github.com/ssciwr/clang-format-wheel
1515
- repo: https://github.com/pre-commit/mirrors-clang-format
1616
rev: v21.1.8
1717
hooks:
18-
- id: clang-format
19-
types_or: [c++, c]
18+
- id: clang-format
19+
types_or: [c++, c]
2020

21-
# CMake linting and formatting
21+
# CMake linting and formatting
2222
- repo: https://github.com/BlankSpruce/gersemi
2323
rev: 0.25.1
2424
hooks:
25-
- id: gersemi
26-
name: CMake linting
27-
exclude: ^.*/tests/.*/data/ # Exclude test data directories
25+
- id: gersemi
26+
name: CMake linting
27+
exclude: ^.*/tests/.*/data/ # Exclude test data directories
2828

29-
# Markdown linting
30-
# Config file: .markdownlint.yaml
31-
# Commented out to disable this by default. Uncomment to enable markdown linting.
29+
# Markdown linting
30+
# Config file: .markdownlint.yaml
31+
# Commented out to disable this by default.
32+
# Uncomment to enable markdown linting.
3233
# - repo: https://github.com/igorshubovych/markdownlint-cli
3334
# rev: v0.42.0
3435
# hooks:
35-
# - id: markdownlint
36+
# - id: markdownlint
3637

3738
- repo: https://github.com/codespell-project/codespell
3839
rev: v2.4.1
3940
hooks:
4041
- id: codespell
42+
additional_dependencies:
43+
- tomli
4144

4245
exclude: 'cookiecutter/|infra/'

include/beman/expected/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33

44
target_sources(
55
beman.expected
6-
PUBLIC FILE_SET HEADERS FILES expected.hpp unexpected.hpp
6+
PUBLIC
7+
FILE_SET HEADERS
8+
FILES expected.hpp unexpected.hpp bad_expected_access.hpp
79
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// beman/expected/bad_expected_access.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
#ifndef BEMAN_EXPECTED_BAD_EXPECTED_ACCESS
4+
#define BEMAN_EXPECTED_BAD_EXPECTED_ACCESS
5+
6+
/***
7+
22.8.4 Class template bad_expected_access[expected.bad]
8+
9+
namespace std {
10+
template<class E>
11+
class bad_expected_access : public bad_expected_access<void> {
12+
public:
13+
constexpr explicit bad_expected_access(E);
14+
constexpr const char* what() const noexcept override;
15+
constexpr E& error() & noexcept;
16+
constexpr const E& error() const & noexcept;
17+
constexpr E&& error() && noexcept;
18+
constexpr const E&& error() const && noexcept;
19+
20+
private:
21+
E unex; // exposition only
22+
};
23+
}
24+
*/
25+
26+
/***
27+
22.8.5 Class template specialization bad_expected_access<void>[expected.bad.void]
28+
namespace std {
29+
template<>
30+
class bad_expected_access<void> : public exception {
31+
protected:
32+
constexpr bad_expected_access() noexcept;
33+
constexpr bad_expected_access(const bad_expected_access&) noexcept;
34+
constexpr bad_expected_access(bad_expected_access&&) noexcept;
35+
constexpr bad_expected_access& operator=(const bad_expected_access&) noexcept;
36+
constexpr bad_expected_access& operator=(bad_expected_access&&) noexcept;
37+
constexpr ~bad_expected_access();
38+
39+
public:
40+
constexpr const char* what() const noexcept override;
41+
};
42+
}
43+
pcc*/
44+
namespace beman {
45+
namespace expected {
46+
47+
48+
}
49+
}
50+
51+
#endif

include/beman/expected/expected.hpp

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,251 @@
33
#ifndef BEMAN_EXPECTED_EXPECTED_HPP
44
#define BEMAN_EXPECTED_EXPECTED_HPP
55

6+
#include <beman/expected/unexpected.hpp>
7+
#include <beman/expected/bad_expected_access.hpp>
8+
9+
/***
10+
22.8.2 Header <expected> synopsis[expected.syn]
11+
12+
// mostly freestanding
13+
namespace std {
14+
// [expected.unexpected], class template unexpected
15+
template<class E> class unexpected;
16+
17+
// [expected.bad], class template bad_expected_access
18+
template<class E> class bad_expected_access;
19+
20+
// [expected.bad.void], specialization for void
21+
template<> class bad_expected_access<void>;
22+
23+
// in-place construction of unexpected values
24+
struct unexpect_t {
25+
explicit unexpect_t() = default;
26+
};
27+
inline constexpr unexpect_t unexpect{};
28+
29+
// [expected.expected], class template expected
30+
template<class T, class E> class expected; // partially freestanding
31+
32+
// [expected.void], partial specialization of expected for void types
33+
template<class T, class E> requires is_void_v<T> class expected<T, E>; // partially freestanding
34+
}
35+
*/
36+
37+
/***
38+
22.8.6 Class template expected[expected.expected]
39+
22.8.6.1 General[expected.object.general]
40+
namespace std {
41+
template<class T, class E>
42+
class expected {
43+
public:
44+
using value_type = T;
45+
using error_type = E;
46+
using unexpected_type = unexpected<E>;
47+
48+
template<class U>
49+
using rebind = expected<U, error_type>;
50+
51+
// [expected.object.cons], constructors
52+
constexpr expected();
53+
constexpr expected(const expected&);
54+
constexpr expected(expected&&) noexcept(see below);
55+
template<class U, class G>
56+
constexpr explicit(see below) expected(const expected<U, G>&);
57+
template<class U, class G>
58+
constexpr explicit(see below) expected(expected<U, G>&&);
59+
60+
template<class U = remove_cv_t<T>>
61+
constexpr explicit(see below) expected(U&& v);
62+
63+
template<class G>
64+
constexpr explicit(see below) expected(const unexpected<G>&);
65+
template<class G>
66+
constexpr explicit(see below) expected(unexpected<G>&&);
67+
68+
template<class... Args>
69+
constexpr explicit expected(in_place_t, Args&&...);
70+
template<class U, class... Args>
71+
constexpr explicit expected(in_place_t, initializer_list<U>, Args&&...);
72+
template<class... Args>
73+
constexpr explicit expected(unexpect_t, Args&&...);
74+
template<class U, class... Args>
75+
constexpr explicit expected(unexpect_t, initializer_list<U>, Args&&...);
76+
77+
// [expected.object.dtor], destructor
78+
constexpr ~expected();
79+
80+
// [expected.object.assign], assignment
81+
constexpr expected& operator=(const expected&);
82+
constexpr expected& operator=(expected&&) noexcept(see below);
83+
template<class U = remove_cv_t<T>> constexpr expected& operator=(U&&);
84+
template<class G>
85+
constexpr expected& operator=(const unexpected<G>&);
86+
template<class G>
87+
constexpr expected& operator=(unexpected<G>&&);
88+
89+
template<class... Args>
90+
constexpr T& emplace(Args&&...) noexcept;
91+
template<class U, class... Args>
92+
constexpr T& emplace(initializer_list<U>, Args&&...) noexcept;
93+
94+
// [expected.object.swap], swap
95+
constexpr void swap(expected&) noexcept(see below);
96+
friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y)));
97+
98+
// [expected.object.obs], observers
99+
constexpr const T* operator->() const noexcept;
100+
constexpr T* operator->() noexcept;
101+
constexpr const T& operator*() const & noexcept;
102+
constexpr T& operator*() & noexcept;
103+
constexpr const T&& operator*() const && noexcept;
104+
constexpr T&& operator*() && noexcept;
105+
constexpr explicit operator bool() const noexcept;
106+
constexpr bool has_value() const noexcept;
107+
constexpr const T& value() const &; // freestanding-deleted
108+
constexpr T& value() &; // freestanding-deleted
109+
constexpr const T&& value() const &&; // freestanding-deleted
110+
constexpr T&& value() &&; // freestanding-deleted
111+
constexpr const E& error() const & noexcept;
112+
constexpr E& error() & noexcept;
113+
constexpr const E&& error() const && noexcept;
114+
constexpr E&& error() && noexcept;
115+
template<class U = remove_cv_t<T>> constexpr T value_or(U&&) const &;
116+
template<class U = remove_cv_t<T>> constexpr T value_or(U&&) &&;
117+
template<class G = E> constexpr E error_or(G&&) const &;
118+
template<class G = E> constexpr E error_or(G&&) &&;
119+
120+
// [expected.object.monadic], monadic operations
121+
template<class F> constexpr auto and_then(F&& f) &;
122+
template<class F> constexpr auto and_then(F&& f) &&;
123+
template<class F> constexpr auto and_then(F&& f) const &;
124+
template<class F> constexpr auto and_then(F&& f) const &&;
125+
template<class F> constexpr auto or_else(F&& f) &;
126+
template<class F> constexpr auto or_else(F&& f) &&;
127+
template<class F> constexpr auto or_else(F&& f) const &;
128+
template<class F> constexpr auto or_else(F&& f) const &&;
129+
template<class F> constexpr auto transform(F&& f) &;
130+
template<class F> constexpr auto transform(F&& f) &&;
131+
template<class F> constexpr auto transform(F&& f) const &;
132+
template<class F> constexpr auto transform(F&& f) const &&;
133+
template<class F> constexpr auto transform_error(F&& f) &;
134+
template<class F> constexpr auto transform_error(F&& f) &&;
135+
template<class F> constexpr auto transform_error(F&& f) const &;
136+
template<class F> constexpr auto transform_error(F&& f) const &&;
137+
138+
// [expected.object.eq], equality operators
139+
template<class T2, class E2> requires (!is_void_v<T2>)
140+
friend constexpr bool operator==(const expected& x, const expected<T2, E2>& y);
141+
template<class T2>
142+
friend constexpr bool operator==(const expected&, const T2&);
143+
template<class E2>
144+
friend constexpr bool operator==(const expected&, const unexpected<E2>&);
145+
146+
private:
147+
bool has_val; // exposition only
148+
union {
149+
T val; // exposition only
150+
E unex; // exposition only
151+
};
152+
};
153+
}
154+
*/
155+
156+
/***
157+
22.8.7 Partial specialization of expected for void types[expected.void]
158+
22.8.7.1 General[expected.void.general]
159+
template<class T, class E> requires is_void_v<T>
160+
class expected<T, E> {
161+
public:
162+
using value_type = T;
163+
using error_type = E;
164+
using unexpected_type = unexpected<E>;
165+
166+
template<class U>
167+
using rebind = expected<U, error_type>;
168+
169+
// [expected.void.cons], constructors
170+
constexpr expected() noexcept;
171+
constexpr expected(const expected&);
172+
constexpr expected(expected&&) noexcept(see below);
173+
template<class U, class G>
174+
constexpr explicit(see below) expected(const expected<U, G>&);
175+
template<class U, class G>
176+
constexpr explicit(see below) expected(expected<U, G>&&);
177+
178+
template<class G>
179+
constexpr explicit(see below) expected(const unexpected<G>&);
180+
template<class G>
181+
constexpr explicit(see below) expected(unexpected<G>&&);
182+
183+
constexpr explicit expected(in_place_t) noexcept;
184+
template<class... Args>
185+
constexpr explicit expected(unexpect_t, Args&&...);
186+
template<class U, class... Args>
187+
constexpr explicit expected(unexpect_t, initializer_list<U>, Args&&...);
188+
189+
190+
// [expected.void.dtor], destructor
191+
constexpr ~expected();
192+
193+
// [expected.void.assign], assignment
194+
constexpr expected& operator=(const expected&);
195+
constexpr expected& operator=(expected&&) noexcept(see below);
196+
template<class G>
197+
constexpr expected& operator=(const unexpected<G>&);
198+
template<class G>
199+
constexpr expected& operator=(unexpected<G>&&);
200+
constexpr void emplace() noexcept;
201+
202+
// [expected.void.swap], swap
203+
constexpr void swap(expected&) noexcept(see below);
204+
friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y)));
205+
206+
// [expected.void.obs], observers
207+
constexpr explicit operator bool() const noexcept;
208+
constexpr bool has_value() const noexcept;
209+
constexpr void operator*() const noexcept;
210+
constexpr void value() const &; // freestanding-deleted
211+
constexpr void value() &&; // freestanding-deleted
212+
constexpr const E& error() const & noexcept;
213+
constexpr E& error() & noexcept;
214+
constexpr const E&& error() const && noexcept;
215+
constexpr E&& error() && noexcept;
216+
template<class G = E> constexpr E error_or(G&&) const &;
217+
template<class G = E> constexpr E error_or(G&&) &&;
218+
219+
// [expected.void.monadic], monadic operations
220+
template<class F> constexpr auto and_then(F&& f) &;
221+
template<class F> constexpr auto and_then(F&& f) &&;
222+
template<class F> constexpr auto and_then(F&& f) const &;
223+
template<class F> constexpr auto and_then(F&& f) const &&;
224+
template<class F> constexpr auto or_else(F&& f) &;
225+
template<class F> constexpr auto or_else(F&& f) &&;
226+
template<class F> constexpr auto or_else(F&& f) const &;
227+
template<class F> constexpr auto or_else(F&& f) const &&;
228+
template<class F> constexpr auto transform(F&& f) &;
229+
template<class F> constexpr auto transform(F&& f) &&;
230+
template<class F> constexpr auto transform(F&& f) const &;
231+
template<class F> constexpr auto transform(F&& f) const &&;
232+
template<class F> constexpr auto transform_error(F&& f) &;
233+
template<class F> constexpr auto transform_error(F&& f) &&;
234+
template<class F> constexpr auto transform_error(F&& f) const &;
235+
template<class F> constexpr auto transform_error(F&& f) const &&;
236+
237+
// [expected.void.eq], equality operators
238+
template<class T2, class E2> requires is_void_v<T2>
239+
friend constexpr bool operator==(const expected& x, const expected<T2, E2>& y);
240+
template<class E2>
241+
friend constexpr bool operator==(const expected&, const unexpected<E2>&);
242+
243+
private:
244+
bool has_val; // exposition only
245+
union {
246+
E unex; // exposition only
247+
};
248+
};
249+
*/
250+
6251
namespace beman {
7252
namespace expected {}
8253
} // namespace beman

0 commit comments

Comments
 (0)