diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-01-22 11:38:37 -0800 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2016-01-22 21:49:52 +0000 |
commit | 0dbbf605efb8f72b3c2c15c14e613323fc2ac0a2 (patch) | |
tree | 5ecb3c53691357a7ebf5d75debb9e612c7b32714 /include | |
parent | 48a8669ddc2e8d785aad9ad18a5abbf8f1224fde (diff) | |
download | libweave-0dbbf605efb8f72b3c2c15c14e613323fc2ac0a2.tar.gz |
AddTo will return AddToTypeProxy for convenience
Change-Id: If86496af0c68af31a3e0c618b0fae861975a4ebf
Reviewed-on: https://weave-review.googlesource.com/2321
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/weave/error.h | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/include/weave/error.h b/include/weave/error.h index 64b99bd..0cf8dc5 100644 --- a/include/weave/error.h +++ b/include/weave/error.h @@ -24,6 +24,21 @@ class LIBWEAVE_EXPORT Error final { public: ~Error() = default; + class AddToTypeProxy { + public: + operator bool() const { return false; } + + template <class T> + operator std::unique_ptr<T>() const { + return nullptr; + } + + template <class T> + operator T*() const { + return nullptr; + } + }; + // Creates an instance of Error class. static ErrorPtr Create(const tracked_objects::Location& location, const std::string& code, @@ -35,17 +50,17 @@ class LIBWEAVE_EXPORT Error final { // If |error| is not nullptr, creates another instance of Error class, // initializes it with specified arguments and adds it to the head of // the error chain pointed to by |error|. - static void AddTo(ErrorPtr* error, - const tracked_objects::Location& location, - const std::string& code, - const std::string& message); + static AddToTypeProxy AddTo(ErrorPtr* error, + const tracked_objects::Location& location, + const std::string& code, + const std::string& message); // Same as the Error::AddTo above, but allows to pass in a printf-like // format string and optional parameters to format the error message. - static void AddToPrintf(ErrorPtr* error, - const tracked_objects::Location& location, - const std::string& code, - const char* format, - ...) PRINTF_FORMAT(4, 5); + static AddToTypeProxy AddToPrintf(ErrorPtr* error, + const tracked_objects::Location& location, + const std::string& code, + const char* format, + ...) PRINTF_FORMAT(4, 5); // Clones error with all inner errors. ErrorPtr Clone() const; |