From e5b5f1a5d46ead5ed610c23363d8922e0404f715 Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Wed, 22 Oct 2014 15:15:52 +0200 Subject: Allow casting a Php::Value to a std::set --- include/value.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/value.h b/include/value.h index 5f387be..85935ec 100644 --- a/include/value.h +++ b/include/value.h @@ -476,6 +476,40 @@ public: return result; } + /** + * Convert the object to a set + * + * This only works for regular arrays that are indexed by a number, start + * with position 0 and have no empty spaces. + * + * return std::vector + */ + template + std::set setValue() const + { + // only works for arrays, other types return an empty set + if (!isArray()) return std::set(); + + // allocate a result + std::set result; + + // how many elements are we inserting + size_t count = size(); + + // and fill the result set + for (size_t i = 0; i(); } + /** + * Convert the object to a set + * @return std::set + */ + template + operator std::set() const + { + return setValue(); + } + /** * Convert the object to a map with string index and Php::Value value * @return std::map -- cgit v1.2.3