Browse Source

Optimised Result::ok()

tags/2021-05-28
jules 12 years ago
parent
commit
30e3b0d865
2 changed files with 10 additions and 10 deletions
  1. +2
    -5
      modules/juce_core/misc/juce_Result.cpp
  2. +8
    -5
      modules/juce_core/misc/juce_Result.h

+ 2
- 5
modules/juce_core/misc/juce_Result.cpp View File

@@ -26,6 +26,8 @@
==============================================================================
*/
Result::Result() noexcept {}
Result::Result (const String& message) noexcept
: errorMessage (message)
{
@@ -65,11 +67,6 @@ bool Result::operator!= (const Result& other) const noexcept
return errorMessage != other.errorMessage;
}
Result Result::ok() noexcept
{
return Result (String::empty);
}
Result Result::fail (const String& errorMessage) noexcept
{
return Result (errorMessage.isEmpty() ? "Unknown Error" : errorMessage);


+ 8
- 5
modules/juce_core/misc/juce_Result.h View File

@@ -65,7 +65,7 @@ class JUCE_API Result
public:
//==============================================================================
/** Creates and returns a 'successful' result. */
static Result ok() noexcept;
static Result ok() noexcept { return Result(); }
/** Creates a 'failure' result.
If you pass a blank error message in here, a default "Unknown Error" message
@@ -99,12 +99,12 @@ public:
const String& getErrorMessage() const noexcept;
//==============================================================================
Result (const Result& other);
Result& operator= (const Result& other);
Result (const Result&);
Result& operator= (const Result&);
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
Result (Result&& other) noexcept;
Result& operator= (Result&& other) noexcept;
Result (Result&&) noexcept;
Result& operator= (Result&&) noexcept;
#endif
bool operator== (const Result& other) const noexcept;
@@ -113,6 +113,9 @@ public:
private:
String errorMessage;
// The default constructor is not for public use!
// Instead, use Result::ok() or Result::fail()
Result() noexcept;
explicit Result (const String&) noexcept;
// These casts are private to prevent people trying to use the Result object in numeric contexts


Loading…
Cancel
Save