diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-07 17:00:53 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-23 13:31:13 -0700 |
commit | d7227e13a7a87cf50a4c8c1f0615fc565f5a2679 (patch) | |
tree | eda76a2da3220f3cfeec901400369cf9c8361f58 /include/mbgl/style/conversion.hpp | |
parent | 1c757cce34344dfecc9a724034680225143f92b7 (diff) | |
download | qtlocation-mapboxgl-d7227e13a7a87cf50a4c8c1f0615fc565f5a2679.tar.gz |
[all] Replace Result<T> with optional<T> plus out Error parameter
Diffstat (limited to 'include/mbgl/style/conversion.hpp')
-rw-r--r-- | include/mbgl/style/conversion.hpp | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index e53adcb942..d6fb3a6dd0 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -1,6 +1,6 @@ #pragma once -#include <mbgl/util/variant.hpp> +#include <mbgl/util/optional.hpp> #include <string> @@ -21,11 +21,11 @@ namespace conversion { A single template function serves as the public interface: template <class T, class V> - Result<T> convert(const V& value); + optional<T> convert(const V& value, Error& error); - Where `T` is one of the above types. If the conversion fails, the `Error` variant of `Result` is - returned, which includes diagnostic text suitable for presentation to a library user. Otherwise, - the `T` variant of `Result` is returned. + Where `T` is one of the above types. If the conversion fails, the result is empty, and the + error parameter includes diagnostic text suitable for presentation to a library user. Otherwise, + a filled optional is returned. The implementation of `convert` requires that the following are legal expressions for a value `v` of type `const V&`: @@ -57,37 +57,12 @@ namespace conversion { struct Error { std::string message; }; -template <class T> -class Result : private variant<T, Error> { -public: - using variant<T, Error>::variant; - - explicit operator bool() const { - return this->template is<T>(); - } - - T& operator*() { - assert(this->template is<T>()); - return this->template get<T>(); - } - - const T& operator*() const { - assert(this->template is<T>()); - return this->template get<T>(); - } - - const Error& error() const { - assert(this->template is<Error>()); - return this->template get<Error>(); - } -}; - template <class T, class Enable = void> struct Converter; template <class T, class V, class...Args> -Result<T> convert(const V& value, Args&&...args) { - return Converter<T>()(value, std::forward<Args>(args)...); +optional<T> convert(const V& value, Error& error, Args&&...args) { + return Converter<T>()(value, error, std::forward<Args>(args)...); } } // namespace conversion |