Skip to content

Commit

Permalink
project Use c++23 std::optional<>'s Monadic apis
Browse files Browse the repository at this point in the history
Also provide an empty string to `std::println()`. `std::println()` without a string is only support in C++26
  • Loading branch information
suhas-pai committed Jan 6, 2025
1 parent 9be0246 commit 5772203
Show file tree
Hide file tree
Showing 25 changed files with 414 additions and 451 deletions.
4 changes: 2 additions & 2 deletions include/ADT/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ namespace ADT {
{
const auto RootDepthLevel = static_cast<uint64_t>(1);
if (NodePrinterFunc(OutFile, /*DepthLevel=*/0, RootDepthLevel, *this)) {
std::println(OutFile);
std::println(OutFile, "");
}

auto Iter = TreeDFSIterator<const TreeNode>(this);
Expand Down Expand Up @@ -607,7 +607,7 @@ namespace ADT {
WrittenOut += 1;

NodePrinterFunc(OutFile, WrittenOut, DepthLevel, Info);
std::println(OutFile);
std::println(OutFile, "");
}

return *this;
Expand Down
11 changes: 5 additions & 6 deletions include/Dyld3/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <optional>
#include <string_view>
#include "Utils/Assert.h"

Expand Down Expand Up @@ -46,7 +47,7 @@ namespace Dyld3 {

[[nodiscard]]
constexpr auto PlatformGetString(const enum Platform Platform) noexcept
-> std::string_view
-> std::optional<std::string_view>
{
switch (Platform) {
case Platform::macOS:
Expand All @@ -71,13 +72,12 @@ namespace Dyld3 {
return "PLATFORM_DRIVERKIT";
}

assert(false &&
"Dyld3::PlatformGetString() called with unknown Platform");
return std::nullopt;
}

[[nodiscard]]
constexpr auto PlatformGetDesc(const enum Platform Platform) noexcept
-> std::string_view
-> std::optional<std::string_view>
{
switch (Platform) {
case Platform::macOS:
Expand All @@ -102,7 +102,6 @@ namespace Dyld3 {
return "DriverKit";
}

assert(false &&
"Dyld3::PlatformGetDesc() called with unknown Platform");
return std::nullopt;
}
}
7 changes: 2 additions & 5 deletions include/DyldSharedCache/Headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ namespace DyldSharedCache {

[[nodiscard]] constexpr
static auto KindGetString(const FlagsStruct::Kind Kind) noexcept
-> std::string_view
-> std::optional<std::string_view>
{
switch (Kind) {
case Kind::IsProduction:
Expand All @@ -376,12 +376,9 @@ namespace DyldSharedCache {
return "Large Shared-Cache";
}

assert(false &&
"DyldSharedCache::ObjcOptimizationHeader::FlagsStruct::"
"KindGetString() got unknown Kind");
return std::nullopt;
}


[[nodiscard]] constexpr auto isProduction() const noexcept {
return valueForMask(Kind::IsProduction);
}
Expand Down
Loading

0 comments on commit 5772203

Please sign in to comment.