errors 0.6.3
Loading...
Searching...
No Matches
make.hpp
1#pragma once
2
3#include <memory>
4
5#include "errors/error_ptr.hpp"
6#include "errors/source_location.hpp"
7
8namespace errors
9{
10namespace detail
11{
13template <typename E>
14class make {
15 private:
16 make() = delete;
17 make(const make &) = delete;
18 make(make &&) = delete;
19 make &operator=(const make &) = delete;
20 make &operator=(make &&) = delete;
21
22 public:
23 template <typename... Args>
24 struct with : public error_ptr {
25 with(Args... args)
26 : error_ptr(std::make_unique<E>(std::move(args)...))
27 {
28 }
29 };
30
32 // See https://www.cppstories.com/2021/non-terminal-variadic-args/
33 template <typename... Args>
34 with(Args...) -> with<Args...>;
36};
38}
39
41template <typename E>
42class make {
43 private:
44 make() = delete;
45 make(const make &) = delete;
46 make(make &&) = delete;
47 make &operator=(const make &) = delete;
48 make &operator=(make &&) = delete;
49
50 public:
52 template <typename... Args>
53 struct with : public error_ptr {
63 with(Args... args,
65 : error_ptr(static_cast<error_ptr>(
66 typename detail::make<E>::with(
67 std::move(args)...,
68 std::move(location))))
69 {
70 }
71 };
73
75 // See https://www.cppstories.com/2021/non-terminal-variadic-args/
76 template <typename... Args>
77 with(Args...) -> with<Args...>;
79};
80
81}
Smart pointer to errors::error with some utility member functions.
Definition error_ptr.hpp:13
Definition make.hpp:42
Definition make.hpp:53
with(Args... args, source_location location=source_location::current())
Create an error.
Definition make.hpp:63
The source location.
Definition source_location.hpp:46
static constexpr source_location current(const char *fileName="unsupported", const char *functionName="unsupported", const uint_least32_t lineNumber=0, const uint_least32_t columnOffset=0) noexcept
Returns the current source location.
Definition source_location.hpp:70