From 20091e94c8a7748306d82fd2907ea8e2aef212eb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 3 Mar 2015 11:50:02 +0100 Subject: [PATCH] fix compilation - remove wrong comments - fix include guard footer - add curly braces - add template specialization for std::vector in make_array - reformat --- util/json_util.hpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/util/json_util.hpp b/util/json_util.hpp index 563440d19..013ada408 100644 --- a/util/json_util.hpp +++ b/util/json_util.hpp @@ -25,9 +25,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// based on -// https://svn.apache.org/repos/asf/mesos/tags/release-0.9.0-incubating-RC0/src/common/json.hpp - #ifndef JSON_UTIL_HPP #define JSON_UTIL_HPP @@ -71,26 +68,39 @@ template osrm::json::Array make_array(Args... args) return a; } -template osrm::json::Array make_array(const std::vector& vector) +template osrm::json::Array make_array(const std::vector &vector) { osrm::json::Array a; - for (const auto& v : vector) + for (const auto &v : vector) + { a.values.emplace_back(v); + } + return a; +} + +// template specialization needed as clang does not play nice +template <> osrm::json::Array make_array(const std::vector &vector) +{ + osrm::json::Array a; + for (const bool v : vector) + { + a.values.emplace_back(v); + } return a; } // Easy acces to object hierachies -osrm::json::Value& get(osrm::json::Value& value) { return value; } +osrm::json::Value &get(osrm::json::Value &value) { return value; } -template -osrm::json::Value& get(osrm::json::Value& value, const char* key, Keys... keys) +template +osrm::json::Value &get(osrm::json::Value &value, const char *key, Keys... keys) { using recursive_object_t = mapbox::util::recursive_wrapper; return get(value.get().get().values[key], keys...); } -template -osrm::json::Value& get(osrm::json::Value& value, unsigned key, Keys... keys) +template +osrm::json::Value &get(osrm::json::Value &value, unsigned key, Keys... keys) { using recursive_array_t = mapbox::util::recursive_wrapper; return get(value.get().get().values[key], keys...); @@ -98,4 +108,4 @@ osrm::json::Value& get(osrm::json::Value& value, unsigned key, Keys... keys) } // namespace json } // namespace osrm -#endif // JSON_RENDERER_HPP +#endif // JSON_UTIL_HPP