From b9836f4a8dc28c2641f027cf47c6604b7268e37f Mon Sep 17 00:00:00 2001 From: John Fremlin VII Date: Mon, 17 Sep 2012 11:14:26 -0700 Subject: [PATCH] add pop_back to arrays Summary: Add a pop_back() function to dynamic arrays. Test Plan: - used it Reviewed By: delong.j@fb.com FB internal diff: D569440 --- folly/dynamic-inl.h | 5 +++++ folly/dynamic.h | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index 58f89710..1942452c 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -646,6 +646,11 @@ inline void dynamic::push_back(dynamic&& v) { array.push_back(std::move(v)); } +inline void dynamic::pop_back() { + auto& array = get(); + array.pop_back(); +} + inline std::size_t dynamic::hash() const { switch (type()) { case OBJECT: diff --git a/folly/dynamic.h b/folly/dynamic.h index 3defcfaf..4f02bd0c 100644 --- a/folly/dynamic.h +++ b/folly/dynamic.h @@ -415,6 +415,14 @@ public: void push_back(dynamic const&); void push_back(dynamic&&); + /* + * Remove an element from the back of an array. If this is not an array, + * throws TypeError. + * + * Does not invalidate iterators. + */ + void pop_back(); + /* * Get a hash code. This function is called by a std::hash<> * specialization, also. -- 2.34.1