Remove dynamic's initializer_list constructor
[folly.git] / folly / dynamic.h
index ef4fdf682d6a792cb42447cada369eaa512295cf..2dc49434cbf32c386e7bf734533efacf3e7ec1b4 100644 (file)
  * @author Jordan DeLong <delong.j@fb.com>
  */
 
-#ifndef FOLLY_DYNAMIC_H_
-#define FOLLY_DYNAMIC_H_
+#pragma once
 
 #include <cstdint>
-#include <initializer_list>
 #include <memory>
 #include <ostream>
 #include <string>
@@ -75,7 +73,6 @@
 
 #include <boost/operators.hpp>
 
-#include <folly/FBString.h>
 #include <folly/Range.h>
 #include <folly/Traits.h>
 
@@ -137,7 +134,6 @@ public:
    *   d["something_else"] = dynamic::array(1, 2, 3, nullptr);
    */
 private:
-  struct PrivateTag {};
   struct EmptyArrayTag {};
   struct ObjectMaker;
 
@@ -158,8 +154,7 @@ public:
   /* implicit */ dynamic(StringPiece val);
   /* implicit */ dynamic(char const* val);
   /* implicit */ dynamic(std::string const& val);
-  /* implicit */ dynamic(fbstring const& val);
-  /* implicit */ dynamic(fbstring&& val);
+  /* implicit */ dynamic(std::string&& val);
 
   /*
    * This is part of the plumbing for array() and object(), above.
@@ -170,23 +165,6 @@ public:
   /* implicit */ dynamic(ObjectMaker const&) = delete;
   /* implicit */ dynamic(ObjectMaker&&);
 
-  /*
-   * Create a new array from an initializer list.
-   *
-   * For example:
-   *
-   *   dynamic v = { 1, 2, 3, "foo" };
-   */
-  // TODO(ott, 10300209): Remove once all uses have been eradicated.
-
-  FOLLY_DEPRECATED(
-      "Initializer list syntax is deprecated (#10300209). Use dynamic::array.")
-  /* implicit */ dynamic(std::initializer_list<dynamic> il);
-  dynamic(std::initializer_list<dynamic> il, PrivateTag);
-  FOLLY_DEPRECATED(
-      "Initializer list syntax is deprecated (#10300209). Use dynamic::array.")
-  dynamic& operator=(std::initializer_list<dynamic> il);
-
   /*
    * Conversion constructors from most of the other types.
    */
@@ -292,7 +270,7 @@ public:
    * since arrays and objects are generally best dealt with as a
    * dynamic.
    */
-  fbstring asString() const;
+  std::string asString() const;
   double   asDouble() const;
   int64_t  asInt() const;
   bool     asBool() const;
@@ -302,15 +280,15 @@ public:
    *
    * These will throw a TypeError if the dynamic has a different type.
    */
-  const fbstring& getString() const&;
+  const std::string& getString() const&;
   double          getDouble() const&;
   int64_t         getInt() const&;
   bool            getBool() const&;
-  fbstring& getString() &;
+  std::string& getString() &;
   double&   getDouble() &;
   int64_t&  getInt() &;
   bool&     getBool() &;
-  fbstring getString() &&;
+  std::string&& getString() &&;
   double   getDouble() &&;
   int64_t  getInt() &&;
   bool     getBool() &&;
@@ -387,7 +365,7 @@ public:
    */
   dynamic const& at(dynamic const&) const&;
   dynamic&       at(dynamic const&) &;
-  dynamic        at(dynamic const&) &&;
+  dynamic&&      at(dynamic const&) &&;
 
   /*
    * Like 'at', above, except it returns either a pointer to the contained
@@ -418,7 +396,7 @@ public:
    */
   dynamic&       operator[](dynamic const&) &;
   dynamic const& operator[](dynamic const&) const&;
-  dynamic        operator[](dynamic const&) &&;
+  dynamic&&      operator[](dynamic const&) &&;
 
   /*
    * Only defined for objects, throws TypeError otherwise.
@@ -433,8 +411,16 @@ public:
   dynamic getDefault(const dynamic& k, dynamic&& v) const&;
   dynamic getDefault(const dynamic& k, const dynamic& v = dynamic::object) &&;
   dynamic getDefault(const dynamic& k, dynamic&& v) &&;
-  template<class K, class V = dynamic>
-  dynamic& setDefault(K&& k, V&& v = dynamic::object);
+  template<class K, class V>
+  dynamic& setDefault(K&& k, V&& v);
+  // MSVC 2015 Update 3 needs these extra overloads because if V were a
+  // defaulted template parameter, it causes MSVC to consider v an rvalue
+  // reference rather than a universal reference, resulting in it not being
+  // able to find the correct overload to construct a dynamic with.
+  template<class K>
+  dynamic& setDefault(K&& k, dynamic&& v);
+  template<class K>
+  dynamic& setDefault(K&& k, const dynamic& v = dynamic::object);
 
   /*
    * Resizes an array so it has at n elements, using the supplied
@@ -539,6 +525,8 @@ private:
   template<class T> struct GetAddrImpl;
   template<class T> struct PrintImpl;
 
+  explicit dynamic(Array&& array);
+
   template<class T> T const& get() const;
   template<class T> T&       get();
   template<class T> T*       get_nothrow() & noexcept;
@@ -567,7 +555,7 @@ private:
     bool boolean;
     double doubl;
     int64_t integer;
-    fbstring string;
+    std::string string;
 
     /*
      * Objects are placement new'd here.  We have to use a char buffer
@@ -588,5 +576,3 @@ private:
 }
 
 #include <folly/dynamic-inl.h>
-
-#endif