From: Louis Brandy Date: Fri, 11 Dec 2015 17:21:43 +0000 (-0800) Subject: folly::dynamic::operator= for std::initializer_list X-Git-Tag: deprecate-dynamic-initializer~188 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=34de70e251592fd4da73ffb8f908ba4e728f385c;p=folly.git folly::dynamic::operator= for std::initializer_list Summary: If we're going to have a constructor for it, we should have operator=. Otherwise, gcc-4.9 goes via the copy constructor effectively "ignoring" the attempted nesting for e.g.. ``` d = { other_dynamic }; // Should be ARRAY containing dynamic ``` NOTE: this only fixes gcc-4.9, there's still issues in clang. Reviewed By: yfeldblum Differential Revision: D2745180 fb-gh-sync-id: 667787c788fc7c131d8a34c608c355f5b875be50 --- diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index 8924fb3d..8bdcf2f4 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -282,6 +282,11 @@ inline dynamic::dynamic(fbstring&& s) new (&u_.string) fbstring(std::move(s)); } +inline dynamic& dynamic::operator=(std::initializer_list il) { + (*this) = dynamic(il); + return *this; +} + inline dynamic::dynamic(std::initializer_list il) : type_(ARRAY) { diff --git a/folly/dynamic.h b/folly/dynamic.h index fa494555..e2ed78a8 100644 --- a/folly/dynamic.h +++ b/folly/dynamic.h @@ -167,6 +167,7 @@ public: * dynamic v = { 1, 2, 3, "foo" }; */ /* implicit */ dynamic(std::initializer_list il); + dynamic& operator=(std::initializer_list il); /* * Conversion constructors from most of the other types.