From d7227e13a7a87cf50a4c8c1f0615fc565f5a2679 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 7 Mar 2017 17:00:53 -0800 Subject: [all] Replace Result with optional plus out Error parameter --- include/mbgl/style/conversion.hpp | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) (limited to 'include/mbgl/style/conversion.hpp') 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 +#include #include @@ -21,11 +21,11 @@ namespace conversion { A single template function serves as the public interface: template - Result convert(const V& value); + optional 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 Result : private variant { -public: - using variant::variant; - - explicit operator bool() const { - return this->template is(); - } - - T& operator*() { - assert(this->template is()); - return this->template get(); - } - - const T& operator*() const { - assert(this->template is()); - return this->template get(); - } - - const Error& error() const { - assert(this->template is()); - return this->template get(); - } -}; - template struct Converter; template -Result convert(const V& value, Args&&...args) { - return Converter()(value, std::forward(args)...); +optional convert(const V& value, Error& error, Args&&...args) { + return Converter()(value, error, std::forward(args)...); } } // namespace conversion -- cgit v1.2.1