-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an exception-less factory type and concept
- Loading branch information
1 parent
9b5b29f
commit 3329a60
Showing
3 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ dplx_target_sources(concrete | |
cncr/type_utils | ||
cncr/utils | ||
cncr/uuid | ||
make | ||
overloaded | ||
scope_guard | ||
) | ||
|
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,36 @@ | ||
|
||
// Copyright 2022-2023 Henrik Steffen Gaßmann | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#pragma once | ||
|
||
#include <concepts> | ||
#include <type_traits> | ||
|
||
#include <dplx/cncr/disappointment.hpp> | ||
|
||
namespace dplx | ||
{ | ||
|
||
template <typename T> | ||
struct make | ||
{ | ||
}; | ||
|
||
// clang-format off | ||
template <typename T> | ||
concept makable | ||
= requires { | ||
typename T; | ||
typename make<T>; | ||
} | ||
&& std::movable<T> | ||
&& requires(make<T> const maker) { | ||
{ maker() } noexcept -> cncr::tryable_result<T>; | ||
}; | ||
// clang-format on | ||
|
||
} // namespace dplx |
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,43 @@ | ||
|
||
// Copyright 2022-2023 Henrik Steffen Gaßmann | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE or copy at | ||
// https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include "dplx/make.hpp" | ||
|
||
#include "test_utils.hpp" | ||
|
||
namespace cncr_tests | ||
{ | ||
|
||
class myhandle | ||
{ | ||
private: | ||
constexpr myhandle() noexcept = default; | ||
|
||
public: | ||
static auto my() noexcept -> result<myhandle> | ||
{ | ||
return myhandle{}; | ||
} | ||
}; | ||
|
||
} // namespace cncr_tests | ||
|
||
template <> | ||
struct dplx::make<cncr_tests::myhandle> | ||
{ | ||
auto operator()() const noexcept -> result<cncr_tests::myhandle> | ||
{ | ||
return cncr_tests::myhandle::my(); | ||
} | ||
}; | ||
|
||
namespace cncr_tests | ||
{ | ||
|
||
static_assert(makable<myhandle>); | ||
|
||
} |