-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0c2d42
commit 1a8b227
Showing
9 changed files
with
108 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
SET(BEMAN_OPTIONAL26_LIBRARY "beman_optional26") | ||
|
||
include(GNUInstallDirs) | ||
|
||
# List of all buildable examples. | ||
set(EXAMPLES | ||
sample | ||
range_loop | ||
optional_ref | ||
) | ||
|
||
foreach(EXAMPLE ${EXAMPLES}) | ||
# Add example executable. | ||
add_executable(${EXAMPLE} "") | ||
|
||
# Add example source file. | ||
target_sources( | ||
${EXAMPLE} | ||
PRIVATE | ||
${EXAMPLE}.cpp | ||
) | ||
|
||
# Link example with the library. | ||
target_link_libraries(${EXAMPLE} "${BEMAN_OPTIONAL26_LIBRARY}") | ||
|
||
# Install . | ||
install( | ||
TARGETS ${EXAMPLE} | ||
EXPORT ${TARGETS_EXPORT_NAME} | ||
DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Beman.Optional26 Examples | ||
|
||
List of usage examples for `Beman.Optional26`. | ||
|
||
## Sample | ||
|
||
Check [sample](sample.cpp) for basic `Beman.Optional26` library usage. | ||
|
||
Build and run instructions: | ||
```shell | ||
# build | ||
$ cmake --workflow --preset gcc-14 | ||
|
||
# run sample | ||
$ .build/gcc-14/examples/RelWithDebInfo/sample | ||
empty_opt is empty! | ||
opt = 26 | ||
``` | ||
|
||
## Range Support (P3168R1) | ||
|
||
Range support added in [*Give std::optional Range Support* (P3168R1)](https://wg21.link/P3168R1) examples: | ||
* [./range_loop.cpp](./range_loop.cpp) | ||
|
||
|
||
Build and run instructions: | ||
|
||
```shell | ||
# build | ||
$ cmake --workflow --preset gcc-14 | ||
|
||
# run range_loop | ||
$ .build/gcc-14/examples/RelWithDebInfo/range_loop | ||
# note: 1st log (empty_opt) is missing from console! | ||
"for each loop" over C++26 optional: opt = 26 # 2nd log (non empty opt) | ||
``` | ||
|
||
## Optional Reference (P2988R5) | ||
|
||
Reference support added in [*std::optional<T&>*(P2988R5)](https://wg21.link/P2988R5) examples: | ||
|
||
* [./optional_ref.cpp](./optional_ref.cpp) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <Beman/Optional26/optional.hpp> | ||
#include <iostream> | ||
|
||
int main() { | ||
beman::optional::optional<int> empty_opt{}; | ||
for ([[maybe_unused]] const auto& i : empty_opt) { | ||
// Should not see this in console. | ||
std::cout << "\"for each loop\" over C++26 optional: empty_opt\n"; | ||
} | ||
|
||
beman::optional::optional<int> opt{26}; | ||
for (const auto& i : opt) { | ||
// Should see this in console. | ||
std::cout << "\"for each loop\" over C++26 optional: opt = " << i << "\n"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <Beman/Optional26/optional.hpp> | ||
#include <print> | ||
|
||
int main() { | ||
beman::optional::optional<int> empty_opt{}; | ||
if (!empty_opt) { | ||
std::println("empty_opt is empty!"); | ||
} | ||
|
||
beman::optional::optional<int> opt{26}; | ||
if (opt) { | ||
std::println("opt = {}", *opt); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
add_subdirectory(beman) | ||
add_subdirectory(examples) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.