-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconstruct.cpp
More file actions
executable file
·49 lines (34 loc) · 1.17 KB
/
Copy pathconstruct.cpp
File metadata and controls
executable file
·49 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright David Stone 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
module;
#include <operators/forward.hpp>
export module bounded.construct;
import bounded.concepts;
import std_module;
namespace bounded {
// TODO: Use lambda https://github.com/llvm/llvm-project/issues/59513
template<typename T>
struct construct_t {
template<typename... Args> requires constructible_from<T, Args &&...>
static constexpr auto operator()(Args && ... args) noexcept(std::is_nothrow_constructible_v<T, Args &&...>) -> T {
return T(OPERATORS_FORWARD(args)...);
}
};
export template<typename T>
constexpr auto construct = construct_t<T>();
} // namespace bounded
namespace {
static_assert(bounded::construct<int>() == 0);
static_assert(bounded::construct<int>(2) == 2);
static_assert(noexcept(bounded::construct<int>()));
struct not_noexcept {
not_noexcept() {}
};
static_assert(!noexcept(bounded::construct<not_noexcept>()));
struct convert_to_int_throws {
operator int() const;
};
static_assert(!noexcept(bounded::construct<int>(convert_to_int_throws())));
} // namespace