Skip to content

Commit

Permalink
Merge pull request #59 from GiovanniDicanio/optimize-regexpected-with…
Browse files Browse the repository at this point in the history
…-move-ctor-overload

Added Move-Semantics Constructor Overload in RegExpected
  • Loading branch information
GiovanniDicanio committed Jul 13, 2022
2 parents ef23e54 + 3d96d0f commit ba6b749
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# WinReg v6.0.1
# WinReg v6.1.0
## High-level C++ Wrapper Around the Low-level Windows Registry C-interface API

by Giovanni Dicanio
Expand Down Expand Up @@ -106,9 +106,13 @@ You can also use the `RegKey::TryGet...Value` methods, that return `RegExpected<
instead of throwing an exception on error:

```c++
//
// RegKey::TryGetDwordValue() returns a RegExpected<DWORD>;
// the returned RegExpected contains a RegResult instance on error.

// the returned RegExpected contains a DWORD on success,
// or a RegResult instance on error.
//
// 'res' is a RegExpected<DWORD> in this case:
//
const auto res = key.TryGetDwordValue(L"SomeDwordValue");
if (res.IsValid()) // or simply: if (res)
{
Expand All @@ -129,7 +133,7 @@ else
}
```

**Version Note:** WinReg v5.1.1 is the latest version in which the `TryGetXxxValue` methods return
**Version Note** WinReg v5.1.1 is the latest version in which the `TryGetXxxValue` methods return
`std::optional<T>` (discarding the information about the error code).
Starting from v6.0.0, the `TryGetXxxxValue` methods return `RegExpected<T>` (which keeps
the error information on failure).
Expand All @@ -149,4 +153,4 @@ The library stuff lives under the `winreg` namespace.
See the [**`WinReg.hpp`**](WinReg/WinReg.hpp) header for more details and **documentation**.

Thanks to everyone who contributed to this project with some additional features and constructive
comments and suggestions.
comments and suggestions.
12 changes: 11 additions & 1 deletion WinReg/WinReg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#include <memory> // std::unique_ptr, std::make_unique
#include <string> // std::wstring
#include <system_error> // std::system_error
#include <utility> // std::swap, std::pair
#include <utility> // std::swap, std::pair, std::move
#include <variant> // std::variant
#include <vector> // std::vector

Expand Down Expand Up @@ -562,6 +562,10 @@ class RegExpected
// Initialize the object with a value (the success case)
explicit RegExpected(const T& value);

// Initialize the object with a value (the success case),
// optimized for move semantics
explicit RegExpected(T&& value);

// Does this object contain a valid value?
[[nodiscard]] explicit operator bool() const noexcept;

Expand Down Expand Up @@ -2777,6 +2781,12 @@ inline RegExpected<T>::RegExpected(const T& value)
{}


template <typename T>
inline RegExpected<T>::RegExpected(T&& value)
: m_var{ std::move(value) }
{}


template <typename T>
inline RegExpected<T>::operator bool() const noexcept
{
Expand Down

0 comments on commit ba6b749

Please sign in to comment.