1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/json
7  
// Official repository: https://github.com/boostorg/json
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_JSON_VALUE_REF_HPP
10  
#ifndef BOOST_JSON_VALUE_REF_HPP
11  
#define BOOST_JSON_VALUE_REF_HPP
11  
#define BOOST_JSON_VALUE_REF_HPP
12  

12  

13  
#include <boost/json/detail/config.hpp>
13  
#include <boost/json/detail/config.hpp>
14  
#include <boost/json/storage_ptr.hpp>
14  
#include <boost/json/storage_ptr.hpp>
15  
#include <boost/json/string.hpp>
15  
#include <boost/json/string.hpp>
16  
#include <initializer_list>
16  
#include <initializer_list>
17  
#include <type_traits>
17  
#include <type_traits>
18  
#include <utility>
18  
#include <utility>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace json {
21  
namespace json {
22  

22  

23  
#ifndef BOOST_JSON_DOCS
23  
#ifndef BOOST_JSON_DOCS
24  
class value;
24  
class value;
25  
class object;
25  
class object;
26  
class array;
26  
class array;
27  
class string;
27  
class string;
28  
#endif
28  
#endif
29  

29  

30  
//----------------------------------------------------------
30  
//----------------------------------------------------------
31  

31  

32  
/** The type used in initializer lists.
32  
/** The type used in initializer lists.
33  

33  

34 -
    This type is used in initializer lists for lazy construction of and
34 +
    This type is used in initializer lists for
35 -
    assignment to the container types @ref value, @ref array, and @ref object.
35 +
    lazy construction of and assignment to the
36 -
    The two types of initializer lists used are:
36 +
    container types @ref value, @ref array,
 
37 +
    and @ref object. The two types of initializer
 
38 +
    lists used are:
37  

39  

38 -
    @li `std::initializer_list< value_ref >` for constructing or assigning
40 +
    @li `std::initializer_list< value_ref >` for
39 -
        a @ref value or @ref array, and
41 +
    constructing or assigning a @ref value or
40 -
    @li `std::initializer_list< std::pair< string_view, value_ref > >` for
42 +
    @ref array, and
41 -
        constructing or assigning an @ref object.
43 +

 
44 +
    @li `std::initializer_list< std::pair< string_view, value_ref > >`
 
45 +
    for constructing or assigning an @ref object.
42  

46  

43  
    A `value_ref` uses reference semantics. Creation of the actual container
47  
    A `value_ref` uses reference semantics. Creation of the actual container
44  
    from the initializer list is lazily deferred until the list is used. This
48  
    from the initializer list is lazily deferred until the list is used. This
45 -
    means that the @ref boost::container::pmr::memory_resource used to
49 +
    means that the `boost::container::pmr::memory_resource` used to construct a
46 -
    construct a container can be specified after the point where the
50 +
    container can be specified after the point where the initializer list is
47 -
    initializer list is specified. Also, the usage of this type allows to avoid
51 +
    specified.
48 -
    constructing a @ref value until it's necessary.
 
49  

52  

50  
    @par Example
53  
    @par Example
51 -
    This example demonstrates how a user-defined type containing a JSON value
54 +

52 -
    can be constructed from an initializer list:
55 +
    This example demonstrates how a user-defined type
 
56 +
    containing a JSON value can be constructed from
 
57 +
    an initializer list:
53  

58  

54  
    @code
59  
    @code
 
60 +

55  
    class my_type
61  
    class my_type
56  
    {
62  
    {
57  
        value jv_;
63  
        value jv_;
58  

64  

59  
    public:
65  
    public:
60 -
        my_type( std::initializer_list<value_ref> init )
66 +
        my_type( std::initializer_list< value_ref > init )
61  
            : jv_(init)
67  
            : jv_(init)
62  
        {
68  
        {
63  
        }
69  
        }
64  
    };
70  
    };
 
71 +

65  
    @endcode
72  
    @endcode
66  

73  

67 -
    @warning `value_ref` does not take ownership of the objects it was
74 +
    @note Never declare a variable of type
68 -
    constructed with. If those objects' lifetimes end before the `value_ref`
75 +
    `std::initializer_list` except in function
69 -
    object is used, you will get undefined behavior. Because of this it is
76 +
    parameter lists, otherwise the behavior may
70 -
    advised against declaring a variable of type
77 +
    be undefined.
71 -
    `std::initializer_list<value_ref>` except in function parameter lists.
 
72  

78  

73 -
    @see @ref value, @ref array, @ref object, @ref value::set_at_pointer.
79 +
    @see
 
80 +
        @ref value,
 
81 +
        @ref array,
 
82 +
        @ref object
74  
*/
83  
*/
75  
class value_ref
84  
class value_ref
76  
{
85  
{
77  
    friend class value;
86  
    friend class value;
78  
    friend class object;
87  
    friend class object;
79  
    friend class array;
88  
    friend class array;
80  

89  

81  
    friend class value_ref_test;
90  
    friend class value_ref_test;
82  

91  

83  
    enum class what
92  
    enum class what
84  
    {
93  
    {
85  
        str,
94  
        str,
86  
        ini,
95  
        ini,
87  
        func,
96  
        func,
88  
        cfunc,
97  
        cfunc,
89  
        strfunc,
98  
        strfunc,
90  
    };
99  
    };
91  

100  

92  
    using init_list =
101  
    using init_list =
93  
        std::initializer_list<value_ref>;
102  
        std::initializer_list<value_ref>;
94  

103  

95  
    struct func_type
104  
    struct func_type
96  
    {
105  
    {
97  
        value(*f)(void*, storage_ptr);
106  
        value(*f)(void*, storage_ptr);
98  
        void* p;
107  
        void* p;
99  
    };
108  
    };
100  

109  

101  
    struct cfunc_type
110  
    struct cfunc_type
102  
    {
111  
    {
103  
        value(*f)(void const*, storage_ptr);
112  
        value(*f)(void const*, storage_ptr);
104  
        void const* p;
113  
        void const* p;
105  
    };
114  
    };
106  

115  

107  
    union arg_type
116  
    union arg_type
108  
    {
117  
    {
109  
        string_view         str_;
118  
        string_view         str_;
110  
        init_list           init_list_;
119  
        init_list           init_list_;
111  

120  

112  
        signed char         schar_;
121  
        signed char         schar_;
113  
        short               short_;
122  
        short               short_;
114  
        int                 int_;
123  
        int                 int_;
115  
        long                long_;
124  
        long                long_;
116  
        long long           long_long_;
125  
        long long           long_long_;
117  
        unsigned char       uchar_;
126  
        unsigned char       uchar_;
118  
        unsigned short      ushort_;
127  
        unsigned short      ushort_;
119  
        unsigned int        uint_;
128  
        unsigned int        uint_;
120  
        unsigned long       ulong_;
129  
        unsigned long       ulong_;
121  
        unsigned long long  ulong_long_;
130  
        unsigned long long  ulong_long_;
122  
        float               float_;
131  
        float               float_;
123  
        double              double_;
132  
        double              double_;
124  
        bool                bool_;
133  
        bool                bool_;
125  
        std::nullptr_t      nullptr_;
134  
        std::nullptr_t      nullptr_;
126  

135  

127  
        arg_type() {}
136  
        arg_type() {}
128  
        explicit arg_type(string_view t) noexcept : str_(t) {}
137  
        explicit arg_type(string_view t) noexcept : str_(t) {}
129  
        explicit arg_type(init_list t) noexcept : init_list_(t) {}
138  
        explicit arg_type(init_list t) noexcept : init_list_(t) {}
130  
        explicit arg_type(signed char t) noexcept : schar_(t) {}
139  
        explicit arg_type(signed char t) noexcept : schar_(t) {}
131  
        explicit arg_type(short t) noexcept : short_(t) {}
140  
        explicit arg_type(short t) noexcept : short_(t) {}
132  
        explicit arg_type(int t) noexcept : int_(t) {}
141  
        explicit arg_type(int t) noexcept : int_(t) {}
133  
        explicit arg_type(long t) noexcept : long_(t) {}
142  
        explicit arg_type(long t) noexcept : long_(t) {}
134  
        explicit arg_type(long long t) noexcept : long_long_(t) {}
143  
        explicit arg_type(long long t) noexcept : long_long_(t) {}
135  
        explicit arg_type(unsigned char t) noexcept : uchar_(t) {}
144  
        explicit arg_type(unsigned char t) noexcept : uchar_(t) {}
136  
        explicit arg_type(unsigned short t) noexcept : ushort_(t) {}
145  
        explicit arg_type(unsigned short t) noexcept : ushort_(t) {}
137  
        explicit arg_type(unsigned int t) noexcept : uint_(t) {}
146  
        explicit arg_type(unsigned int t) noexcept : uint_(t) {}
138  
        explicit arg_type(unsigned long t) noexcept : ulong_(t) {}
147  
        explicit arg_type(unsigned long t) noexcept : ulong_(t) {}
139  
        explicit arg_type(unsigned long long t) noexcept : ulong_long_(t) {}
148  
        explicit arg_type(unsigned long long t) noexcept : ulong_long_(t) {}
140  
        explicit arg_type(float t) noexcept : float_(t) {}
149  
        explicit arg_type(float t) noexcept : float_(t) {}
141  
        explicit arg_type(double t) noexcept : double_(t) {}
150  
        explicit arg_type(double t) noexcept : double_(t) {}
142  
        explicit arg_type(bool t) noexcept : bool_(t) {}
151  
        explicit arg_type(bool t) noexcept : bool_(t) {}
143  
        explicit arg_type(std::nullptr_t) noexcept : nullptr_() {}
152  
        explicit arg_type(std::nullptr_t) noexcept : nullptr_() {}
144  
    };
153  
    };
145  

154  

146  
    arg_type arg_;
155  
    arg_type arg_;
147  
#ifndef BOOST_JSON_DOCS
156  
#ifndef BOOST_JSON_DOCS
148  
    // VFALCO doc toolchain erroneously
157  
    // VFALCO doc toolchain erroneously
149  
    // displays private, anonymous unions as public
158  
    // displays private, anonymous unions as public
150  
    union
159  
    union
151  
    {
160  
    {
152  
        func_type f_;
161  
        func_type f_;
153  
        cfunc_type cf_;
162  
        cfunc_type cf_;
154  
    };
163  
    };
155  
#endif
164  
#endif
156  
    what what_;
165  
    what what_;
157  

166  

158  
public:
167  
public:
159 -
    /** Constructors.
168 +
    /// Constructor
160 -

 
161 -
        @li **(1)** copy constructor.
 
162 -
        @li **(2)** move constructor.
 
163 -
        @li **(3)** the constructed value stores a reference to `t`'s character
 
164 -
            array.
 
165 -
        @li **(4)** the constructed value stores a `const` reference to `t`.
 
166 -
        @li **(5)** the constructed value stores an rvalue reference to `t`.
 
167 -
        @li **(6)** the constructed value stores a copy of `b`.
 
168 -
        @li **(7)**--**(18)** the constructed value stores a copy of `t`.
 
169 -
        @li **(19)** the constrcuted value stores `nullptr`.
 
170 -
        @li **(20)** the constrcuted value stores a copy of `init`.
 
171 -

 
172 -
        In addition the constructed object stores a pointer to a function that
 
173 -
        captures the type information necessary to construct a @ref value from
 
174 -
        the stored data.
 
175 -

 
176 -
        @warning The overloads that accept references do not take ownership of
 
177 -
        referenced objects. The caller is responsible for making sure those
 
178 -
        objects do not go out of scope before the `value_ref` object is used.
 
179 -
        It is advised you only use `value_ref` (or any type that contains a
 
180 -
        `value_ref` subobject) as function parameters or take special care to
 
181 -
        not invoke undefeined behavior.
 
182 -

 
183 -
        @par Complexity
 
184 -
        @li **(1)**--**(19)** constant.
 
185 -
        @li **(20)** linear in `init.size()`.
 
186 -

 
187 -
        @par Exception Safety
 
188 -
        No-throw guarantee.
 
189 -

 
190 -
        @{
 
191 -
    */
 
192  
    value_ref(
169  
    value_ref(
193  
        value_ref const&) = default;
170  
        value_ref const&) = default;
194  

171  

195 -
    /// Overload
172 +
    /// Constructor
196  
    value_ref(
173  
    value_ref(
197  
        value_ref&&) = default;
174  
        value_ref&&) = default;
198  

175  

199 -
    /// Overload
176 +
    /// Constructor
200  
#ifdef BOOST_JSON_DOCS
177  
#ifdef BOOST_JSON_DOCS
201  
    value_ref(string_view s) noexcept;
178  
    value_ref(string_view s) noexcept;
202  
#else
179  
#else
203  
    template<
180  
    template<
204  
        class T
181  
        class T
205  
        ,class = typename
182  
        ,class = typename
206  
            std::enable_if<
183  
            std::enable_if<
207  
                std::is_constructible<
184  
                std::is_constructible<
208  
                    string_view, T>::value>::type
185  
                    string_view, T>::value>::type
209  
    >
186  
    >
210  
    value_ref(
187  
    value_ref(
211  
        T const& t) noexcept
188  
        T const& t) noexcept
212  
        : arg_(string_view(t))
189  
        : arg_(string_view(t))
213  
        , what_(what::str)
190  
        , what_(what::str)
214  
    {
191  
    {
 
192 +

215  
    }
193  
    }
216  
#endif
194  
#endif
217  

195  

218 -
    /// Overload
196 +
    /// Constructor
219  
    template<class T>
197  
    template<class T>
220  
    value_ref(
198  
    value_ref(
221  
        T const& t
199  
        T const& t
222  
#ifndef BOOST_JSON_DOCS
200  
#ifndef BOOST_JSON_DOCS
223  
        ,typename std::enable_if<
201  
        ,typename std::enable_if<
224  
            ! std::is_constructible<
202  
            ! std::is_constructible<
225  
                string_view, T>::value &&
203  
                string_view, T>::value &&
226  
            ! std::is_same<bool, T>::value
204  
            ! std::is_same<bool, T>::value
227  
                >::type* = 0
205  
                >::type* = 0
228  
#endif
206  
#endif
229  
        ) noexcept
207  
        ) noexcept
230  
        : cf_{&from_const<T>, &t}
208  
        : cf_{&from_const<T>, &t}
231  
        , what_(what::cfunc)
209  
        , what_(what::cfunc)
232  
    {
210  
    {
233  
    }
211  
    }
234  

212  

235 -
    /// Overload
213 +
    /// Constructor
236  
    template<class T>
214  
    template<class T>
237  
    value_ref(
215  
    value_ref(
238  
        T&& t
216  
        T&& t
239  
#ifndef BOOST_JSON_DOCS
217  
#ifndef BOOST_JSON_DOCS
240  
        ,typename std::enable_if<
218  
        ,typename std::enable_if<
241  
            (! std::is_constructible<
219  
            (! std::is_constructible<
242  
                string_view, T>::value ||
220  
                string_view, T>::value ||
243  
            std::is_same<string, T>::value) &&
221  
            std::is_same<string, T>::value) &&
244  
            ! std::is_same<bool,
222  
            ! std::is_same<bool,
245  
                detail::remove_cvref<T>>::value &&
223  
                detail::remove_cvref<T>>::value &&
246  
            std::is_same<T, detail::remove_cvref<T>>
224  
            std::is_same<T, detail::remove_cvref<T>>
247  
                ::value>::type* = 0
225  
                ::value>::type* = 0
248  
#endif
226  
#endif
249  
        ) noexcept
227  
        ) noexcept
250  
        : f_{&from_rvalue<
228  
        : f_{&from_rvalue<
251  
            detail::remove_cvref<T>>, &t}
229  
            detail::remove_cvref<T>>, &t}
252  
        , what_(std::is_same<string, T>::value ?
230  
        , what_(std::is_same<string, T>::value ?
253  
                what::strfunc : what::func)
231  
                what::strfunc : what::func)
254  
    {
232  
    {
255  
    }
233  
    }
256  

234  

257 -
    /// Overload
235 +
    /// Constructor
258  
#ifdef BOOST_JSON_DOCS
236  
#ifdef BOOST_JSON_DOCS
259  
    value_ref(bool b) noexcept;
237  
    value_ref(bool b) noexcept;
260  
#else
238  
#else
261  
    template<
239  
    template<
262  
        class T
240  
        class T
263  
        ,class = typename std::enable_if<
241  
        ,class = typename std::enable_if<
264  
            std::is_same<T, bool>::value>::type
242  
            std::is_same<T, bool>::value>::type
265  
    >
243  
    >
266  
    value_ref(
244  
    value_ref(
267  
        T b) noexcept
245  
        T b) noexcept
268  
        : arg_(b)
246  
        : arg_(b)
269  
        , cf_{&from_builtin<bool>, &arg_.bool_}
247  
        , cf_{&from_builtin<bool>, &arg_.bool_}
270  
        , what_(what::cfunc)
248  
        , what_(what::cfunc)
271  
    {
249  
    {
272  
    }
250  
    }
273  
#endif
251  
#endif
274  

252  

275 -
    /// Overload
253 +
    /// Constructor
 
254 +
    value_ref(
 
255 +
        std::initializer_list<
 
256 +
            value_ref> t) noexcept
 
257 +
        : arg_(t)
 
258 +
        , what_(what::ini)
 
259 +
    {
 
260 +
    }
 
261 +

 
262 +
    /// Constructor
276  
    value_ref(signed char t) noexcept
263  
    value_ref(signed char t) noexcept
277  
        : arg_(t)
264  
        : arg_(t)
278  
        , cf_{&from_builtin<signed char>, &arg_.schar_}
265  
        , cf_{&from_builtin<signed char>, &arg_.schar_}
279  
        , what_(what::cfunc)
266  
        , what_(what::cfunc)
280  
    {
267  
    {
281  
    }
268  
    }
282  

269  

283 -
    /// Overload
270 +
    /// Constructor
284  
    value_ref(short t) noexcept
271  
    value_ref(short t) noexcept
285  
        : arg_(t)
272  
        : arg_(t)
286  
        , cf_{&from_builtin<short>, &arg_.short_}
273  
        , cf_{&from_builtin<short>, &arg_.short_}
287  
        , what_(what::cfunc)
274  
        , what_(what::cfunc)
288  
    {
275  
    {
289  
    }
276  
    }
290  

277  

291 -
    /// Overload
278 +
    /// Constructor
292  
    value_ref(int t) noexcept
279  
    value_ref(int t) noexcept
293  
        : arg_(t)
280  
        : arg_(t)
294  
        , cf_{&from_builtin<int>, &arg_.int_}
281  
        , cf_{&from_builtin<int>, &arg_.int_}
295  
        , what_(what::cfunc)
282  
        , what_(what::cfunc)
296  
    {
283  
    {
297  
    }
284  
    }
298  

285  

299 -
    /// Overload
286 +
    /// Constructor
300  
    value_ref(long t) noexcept
287  
    value_ref(long t) noexcept
301  
        : arg_(t)
288  
        : arg_(t)
302  
        , cf_{&from_builtin<
289  
        , cf_{&from_builtin<
303  
            long>, &arg_.long_}
290  
            long>, &arg_.long_}
304  
        , what_(what::cfunc)
291  
        , what_(what::cfunc)
305  
    {
292  
    {
306  
    }
293  
    }
307  

294  

308 -
    /// Overload
295 +
    /// Constructor
309  
    value_ref(long long t) noexcept
296  
    value_ref(long long t) noexcept
310  
        : arg_(t)
297  
        : arg_(t)
311  
        , cf_{&from_builtin<
298  
        , cf_{&from_builtin<
312  
            long long>, &arg_.long_long_}
299  
            long long>, &arg_.long_long_}
313  
        , what_(what::cfunc)
300  
        , what_(what::cfunc)
314  
    {
301  
    {
315  
    }
302  
    }
316  

303  

317 -
    /// Overload
304 +
    /// Constructor
318  
    value_ref(unsigned char t) noexcept
305  
    value_ref(unsigned char t) noexcept
319  
        : arg_(t)
306  
        : arg_(t)
320  
        , cf_{&from_builtin<
307  
        , cf_{&from_builtin<
321  
            unsigned char>, &arg_.uchar_}
308  
            unsigned char>, &arg_.uchar_}
322  
        , what_(what::cfunc)
309  
        , what_(what::cfunc)
323  
    {
310  
    {
324  
    }
311  
    }
325  

312  

326 -
    /// Overload
313 +
    /// Constructor
327  
    value_ref(unsigned short t) noexcept
314  
    value_ref(unsigned short t) noexcept
328  
        : arg_(t)
315  
        : arg_(t)
329  
        , cf_{&from_builtin<
316  
        , cf_{&from_builtin<
330  
            unsigned short>, &arg_.ushort_}
317  
            unsigned short>, &arg_.ushort_}
331  
        , what_(what::cfunc)
318  
        , what_(what::cfunc)
332  
    {
319  
    {
333  
    }
320  
    }
334  

321  

335 -
    /// Overload
322 +
    /// Constructor
336  
    value_ref(unsigned int t) noexcept
323  
    value_ref(unsigned int t) noexcept
337  
        : arg_(t)
324  
        : arg_(t)
338  
        , cf_{&from_builtin<
325  
        , cf_{&from_builtin<
339  
            unsigned int>, &arg_.uint_}
326  
            unsigned int>, &arg_.uint_}
340  
        , what_(what::cfunc)
327  
        , what_(what::cfunc)
341  
    {
328  
    {
342  
    }
329  
    }
343  

330  

344 -
    /// Overload
331 +
    /// Constructor
345  
    value_ref(unsigned long t) noexcept
332  
    value_ref(unsigned long t) noexcept
346  
        : arg_(t)
333  
        : arg_(t)
347  
        , cf_{&from_builtin<
334  
        , cf_{&from_builtin<
348  
            unsigned long>, &arg_.ulong_}
335  
            unsigned long>, &arg_.ulong_}
349  
        , what_(what::cfunc)
336  
        , what_(what::cfunc)
350  
    {
337  
    {
351  
    }
338  
    }
352  

339  

353 -
    /// Overload
340 +
    /// Constructor
354  
    value_ref(unsigned long long t) noexcept
341  
    value_ref(unsigned long long t) noexcept
355  
        : arg_(t)
342  
        : arg_(t)
356  
        , cf_{&from_builtin<
343  
        , cf_{&from_builtin<
357  
            unsigned long long>, &arg_.ulong_long_}
344  
            unsigned long long>, &arg_.ulong_long_}
358  
        , what_(what::cfunc)
345  
        , what_(what::cfunc)
359  
    {
346  
    {
360  
    }
347  
    }
361  

348  

362 -
    /// Overload
349 +
    /// Constructor
363  
    value_ref(float t) noexcept
350  
    value_ref(float t) noexcept
364  
        : arg_(t)
351  
        : arg_(t)
365  
        , cf_{&from_builtin<
352  
        , cf_{&from_builtin<
366  
            float>, &arg_.float_}
353  
            float>, &arg_.float_}
367  
        , what_(what::cfunc)
354  
        , what_(what::cfunc)
368  
    {
355  
    {
369  
    }
356  
    }
370  

357  

371 -
    /// Overload
358 +
    /// Constructor
372  
    value_ref(double t) noexcept
359  
    value_ref(double t) noexcept
373  
        : arg_(t)
360  
        : arg_(t)
374  
        , cf_{&from_builtin<
361  
        , cf_{&from_builtin<
375  
            double>, &arg_.double_}
362  
            double>, &arg_.double_}
376  
        , what_(what::cfunc)
363  
        , what_(what::cfunc)
377  
    {
364  
    {
378  
    }
365  
    }
379  

366  

380 -
    /// Overload
367 +
    /// Constructor
381  
    value_ref(std::nullptr_t) noexcept
368  
    value_ref(std::nullptr_t) noexcept
382  
        : arg_(nullptr)
369  
        : arg_(nullptr)
383  
        , cf_{&from_builtin<
370  
        , cf_{&from_builtin<
384  
            std::nullptr_t>, &arg_.nullptr_}
371  
            std::nullptr_t>, &arg_.nullptr_}
385  
        , what_(what::cfunc)
372  
        , what_(what::cfunc)
386  
    {
373  
    {
387 -

 
388 -
    /// Overload
 
389 -
    value_ref(
 
390 -
        std::initializer_list<value_ref> init) noexcept
 
391 -
        : arg_(init)
 
392 -
        , what_(what::ini)
 
393 -
    {
 
394 -
    }
 
395 -

 
396 -
    /// @}
 
397  
    }
374  
    }
398  

375  

399  
#ifndef BOOST_JSON_DOCS
376  
#ifndef BOOST_JSON_DOCS
400  
// Not public
377  
// Not public
401  
//private:
378  
//private:
402  
    // VFALCO Why is this needed?
379  
    // VFALCO Why is this needed?
403  
    /** Operator conversion to @ref value
380  
    /** Operator conversion to @ref value
404  

381  

405  
        This allows creation of a @ref value from
382  
        This allows creation of a @ref value from
406  
        an initializer list element.
383  
        an initializer list element.
407  
    */
384  
    */
408  
    BOOST_JSON_DECL
385  
    BOOST_JSON_DECL
409  
    operator value() const;
386  
    operator value() const;
410  
#endif
387  
#endif
411  

388  

412  
private:
389  
private:
413  
    template<class T>
390  
    template<class T>
414  
    static
391  
    static
415  
    value
392  
    value
416  
    from_builtin(
393  
    from_builtin(
417  
        void const* p,
394  
        void const* p,
418  
        storage_ptr sp) noexcept;
395  
        storage_ptr sp) noexcept;
419  

396  

420  
    template<class T>
397  
    template<class T>
421  
    static
398  
    static
422  
    value
399  
    value
423  
    from_const(
400  
    from_const(
424  
        void const* p,
401  
        void const* p,
425  
        storage_ptr sp);
402  
        storage_ptr sp);
426  

403  

427  
    template<class T>
404  
    template<class T>
428  
    static
405  
    static
429  
    value
406  
    value
430  
    from_rvalue(
407  
    from_rvalue(
431  
        void* p,
408  
        void* p,
432  
        storage_ptr sp);
409  
        storage_ptr sp);
433  

410  

434  
    static
411  
    static
435  
    BOOST_JSON_DECL
412  
    BOOST_JSON_DECL
436  
    value
413  
    value
437  
    from_init_list(
414  
    from_init_list(
438  
        void const* p,
415  
        void const* p,
439  
        storage_ptr sp);
416  
        storage_ptr sp);
440  

417  

441  
    inline
418  
    inline
442  
    bool
419  
    bool
443  
    is_key_value_pair() const noexcept;
420  
    is_key_value_pair() const noexcept;
444  

421  

445  
    static
422  
    static
446  
    inline
423  
    inline
447  
    bool
424  
    bool
448  
    maybe_object(
425  
    maybe_object(
449  
        std::initializer_list<
426  
        std::initializer_list<
450  
            value_ref> init) noexcept;
427  
            value_ref> init) noexcept;
451  

428  

452  
    inline
429  
    inline
453  
    string_view
430  
    string_view
454  
    get_string() const noexcept;
431  
    get_string() const noexcept;
455  

432  

456  
    BOOST_JSON_DECL
433  
    BOOST_JSON_DECL
457  
    value
434  
    value
458  
    make_value(
435  
    make_value(
459  
        storage_ptr sp) const;
436  
        storage_ptr sp) const;
460  

437  

461  
    BOOST_JSON_DECL
438  
    BOOST_JSON_DECL
462  
    static
439  
    static
463  
    value
440  
    value
464  
    make_value(
441  
    make_value(
465  
        std::initializer_list<
442  
        std::initializer_list<
466  
            value_ref> init,
443  
            value_ref> init,
467  
        storage_ptr sp);
444  
        storage_ptr sp);
468  

445  

469  
    BOOST_JSON_DECL
446  
    BOOST_JSON_DECL
470  
    static
447  
    static
471  
    object
448  
    object
472  
    make_object(
449  
    make_object(
473  
        std::initializer_list<value_ref> init,
450  
        std::initializer_list<value_ref> init,
474  
        storage_ptr sp);
451  
        storage_ptr sp);
475  

452  

476  
    BOOST_JSON_DECL
453  
    BOOST_JSON_DECL
477  
    static
454  
    static
478  
    array
455  
    array
479  
    make_array(
456  
    make_array(
480  
        std::initializer_list<
457  
        std::initializer_list<
481  
            value_ref> init,
458  
            value_ref> init,
482  
        storage_ptr sp);
459  
        storage_ptr sp);
483  

460  

484  
    BOOST_JSON_DECL
461  
    BOOST_JSON_DECL
485  
    static
462  
    static
486  
    void
463  
    void
487  
    write_array(
464  
    write_array(
488  
        value* dest,
465  
        value* dest,
489  
        std::initializer_list<
466  
        std::initializer_list<
490  
            value_ref> init,
467  
            value_ref> init,
491  
        storage_ptr const& sp);
468  
        storage_ptr const& sp);
492  
};
469  
};
493  

470  

494  
} // namespace json
471  
} // namespace json
495  
} // namespace boost
472  
} // namespace boost
496  

473  

497  
// Must be included here for this file to stand alone
474  
// Must be included here for this file to stand alone
498  
#include <boost/json/value.hpp>
475  
#include <boost/json/value.hpp>
499  

476  

500  
// includes are at the bottom of <boost/json/value.hpp>
477  
// includes are at the bottom of <boost/json/value.hpp>
501  
//#include <boost/json/impl/value.hpp>
478  
//#include <boost/json/impl/value.hpp>
502  
//#include <boost/json/impl/value.ipp>
479  
//#include <boost/json/impl/value.ipp>
503  

480  

504  
#endif
481  
#endif