File tree Expand file tree Collapse file tree 4 files changed +21
-7
lines changed
Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 1- cxx_library (
1+ prebuilt_cxx_library (
22 name = 'neither' ,
3+ header_only = True ,
34 header_namespace = 'neither' ,
45 exported_headers = subdir_glob ([
56 ('neither/include' , '**/*.hpp' ),
67 ]),
8+ licenses = [
9+ 'LICENSE.txt' ,
10+ ],
711 visibility = [
8- 'PUBLIC' ,
12+ 'PUBLIC'
913 ],
1014)
1115
@@ -14,9 +18,10 @@ cxx_test(
1418 srcs = glob ([
1519 'neither/tests/**/*.cpp' ,
1620 ]),
17- platform_compiler_flags = [
18- ('^linux.*' , [ '-lpthread' ]),
21+ platform_linker_flags = [
22+ ('^linux.*' , [ '-lpthread' , ]),
1923 ],
24+ link_style = 'shared' ,
2025 deps = [
2126 ':neither' ,
2227 ],
File renamed without changes.
Original file line number Diff line number Diff line change 22#define NEITHER_MAYBE_HPP
33
44#include < memory>
5+ #include < cassert>
56#include < neither/traits.hpp>
67
78namespace neither {
@@ -38,9 +39,12 @@ template <class T> struct Maybe {
3839 }
3940
4041 constexpr T get (T defaultValue) {
41- if (hasValue)
42- return value;
43- return defaultValue;
42+ return hasValue ? value : defaultValue;
43+ }
44+
45+ constexpr T unsafeGet () {
46+ assert (hasValue && " unsafeGet must not be called on an empty Maybe" );
47+ return value;
4448 }
4549
4650 template <class F >
Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ TEST(neither, maybe_flatMap_no_value) {
2828 ASSERT_TRUE (x.flatMap ([](auto x) { return maybe<int >(); }).get (1 ) == 1 );
2929}
3030
31+ TEST (neither, maybe_unsafe_get_with_value) {
32+ auto x = maybe<int >(42 );
33+ ASSERT_TRUE (x.unsafeGet () == 42 );
34+ }
35+
3136TEST (neither, maybe_comparison) {
3237
3338 auto a = maybe<int >(42 );
You can’t perform that action at this time.
0 commit comments