Commit 34de70e2 authored by Louis Brandy's avatar Louis Brandy Committed by facebook-github-bot-1

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
parent bf8a9074
...@@ -282,6 +282,11 @@ inline dynamic::dynamic(fbstring&& s) ...@@ -282,6 +282,11 @@ inline dynamic::dynamic(fbstring&& s)
new (&u_.string) fbstring(std::move(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) inline dynamic::dynamic(std::initializer_list<dynamic> il)
: type_(ARRAY) : type_(ARRAY)
{ {
......
...@@ -167,6 +167,7 @@ public: ...@@ -167,6 +167,7 @@ public:
* dynamic v = { 1, 2, 3, "foo" }; * dynamic v = { 1, 2, 3, "foo" };
*/ */
/* implicit */ dynamic(std::initializer_list<dynamic> il); /* implicit */ dynamic(std::initializer_list<dynamic> il);
dynamic& operator=(std::initializer_list<dynamic> il);
/* /*
* Conversion constructors from most of the other types. * Conversion constructors from most of the other types.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment