folly::dynamic::operator= for std::initializer_list
authorLouis Brandy <ldbrandy@fb.com>
Fri, 11 Dec 2015 17:21:43 +0000 (09:21 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Fri, 11 Dec 2015 18:20:23 +0000 (10:20 -0800)
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

folly/dynamic-inl.h
folly/dynamic.h

index 8924fb3d9bff7641b10ced941fe84c532da5c7e8..8bdcf2f40f3c6b8fc4f013bedec1e879b3774e86 100644 (file)
@@ -282,6 +282,11 @@ inline dynamic::dynamic(fbstring&& s)
   new (&u_.string) fbstring(std::move(s));
 }
 
+inline dynamic& dynamic::operator=(std::initializer_list<dynamic> il) {
+  (*this) = dynamic(il);
+  return *this;
+}
+
 inline dynamic::dynamic(std::initializer_list<dynamic> il)
   : type_(ARRAY)
 {
index fa494555ba2174108cdf1597b7e84fdd35c8185b..e2ed78a8cb23b967c229343a68be62c05a9260c7 100644 (file)
@@ -167,6 +167,7 @@ public:
    *   dynamic v = { 1, 2, 3, "foo" };
    */
   /* implicit */ dynamic(std::initializer_list<dynamic> il);
+  dynamic& operator=(std::initializer_list<dynamic> il);
 
   /*
    * Conversion constructors from most of the other types.