Skip to content

Commit cd82335

Browse files
authored
backport c++23 std::expected (#40)
After studied [0], [1] and [2], I'm inclined to backport [0] to iceberg-cpp, the main reason is that [0] has exactly the same APIs as std::expected, [1] provide some extra member functions like `map` and `map_error`, [2] has different API names like `then` and `thenOrThrow`. We want users to use iceberg::expected the same way as std::expected, and we will replace iceberg::expected with std::expected when we decide to move to c++23 some day, by backporting [0], we can facilitate a smoother transition process. We discussed about `Exceptions vs Expected` in #14, while backporting [0], I had the feeling we shouldn't choose one over the other, we can use both approaches effectively. expected provide monadic operations like `and_then`, `transform`, `or_else`, `transform_error`, let us do method chaining, which is a good sign. [0] https://github.com/zeus-cpp/expected [1] https://github.com/TartanLlama/expected [2] https://github.com/facebook/folly/blob/main/folly/Expected.h [3] https://en.cppreference.com/w/cpp/utility/expected --------- Signed-off-by: Junwang Zhao <[email protected]>
1 parent 17c500a commit cd82335

File tree

7 files changed

+3026
-0
lines changed

7 files changed

+3026
-0
lines changed

.github/.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ header:
1111
- '.github/**'
1212
- 'LICENSE'
1313
- 'NOTICE'
14+
- 'src/iceberg/expected.h'
1415

1516
comment: on-failure

.github/workflows/cpp-linter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
with:
4545
style: file
4646
tidy-checks: ''
47+
version: 19
4748
files-changed-only: true
4849
lines-changed-only: true
4950
thread-comments: true

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,31 @@
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202+
203+
--------------------------------------------------------------------------------
204+
205+
The file src/iceberg/expected.h contains code adapted from
206+
207+
https://github.com/zeus-cpp/expected
208+
209+
with the following license (MIT)
210+
211+
Copyright (c) 2024 zeus-cpp
212+
213+
Permission is hereby granted, free of charge, to any person obtaining a copy
214+
of this software and associated documentation files (the "Software"), to deal
215+
in the Software without restriction, including without limitation the rights
216+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
217+
copies of the Software, and to permit persons to whom the Software is
218+
furnished to do so, subject to the following conditions:
219+
220+
The above copyright notice and this permission notice shall be included in all
221+
copies or substantial portions of the Software.
222+
223+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
224+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
225+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
226+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
227+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
228+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
229+
SOFTWARE.

NOTICE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ Copyright 2024-2025 The Apache Software Foundation
33

44
This product includes software developed at
55
The Apache Software Foundation (http://www.apache.org/).
6+
7+
This product includes code from zeus-cpp
8+
* Copyright (c) 2024 zeus-cpp
9+
* https://github.com/zeus-cpp/expected

0 commit comments

Comments
 (0)