@@ -269,151 +269,11 @@ class Variant
269269 " \n did you accidentally put braces around the default value?" );
270270 }
271271
272- Variant (const Variant& other) : mType (other.mType )
273- {
274- // In case this is an array we need to duplicate it to avoid
275- // double deletion.
276- switch (mType ) {
277- case variant_trait_v<const char *>:
278- mSize = other.mSize ;
279- variant_helper<storage_t , const char *>::set (&mStore , other.get <const char *>());
280- return ;
281- case variant_trait_v<int *>:
282- mSize = other.mSize ;
283- variant_helper<storage_t , int *>::set (&mStore , other.get <int *>(), mSize );
284- return ;
285- case variant_trait_v<float *>:
286- mSize = other.mSize ;
287- variant_helper<storage_t , float *>::set (&mStore , other.get <float *>(), mSize );
288- return ;
289- case variant_trait_v<double *>:
290- mSize = other.mSize ;
291- variant_helper<storage_t , double *>::set (&mStore , other.get <double *>(), mSize );
292- return ;
293- case variant_trait_v<bool *>:
294- mSize = other.mSize ;
295- variant_helper<storage_t , bool *>::set (&mStore , other.get <bool *>(), mSize );
296- return ;
297- case variant_trait_v<std::string*>:
298- mSize = other.mSize ;
299- variant_helper<storage_t , std::string*>::set (&mStore , other.get <std::string*>(), mSize );
300- return ;
301- default :
302- mStore = other.mStore ;
303- mSize = other.mSize ;
304- }
305- }
306-
307- Variant (Variant&& other) : mType (other.mType )
308- {
309- mStore = other.mStore ;
310- mSize = other.mSize ;
311- switch (mType ) {
312- case variant_trait_v<const char *>:
313- *reinterpret_cast <char **>(&(other.mStore )) = nullptr ;
314- return ;
315- case variant_trait_v<int *>:
316- *reinterpret_cast <int **>(&(other.mStore )) = nullptr ;
317- return ;
318- case variant_trait_v<float *>:
319- *reinterpret_cast <float **>(&(other.mStore )) = nullptr ;
320- return ;
321- case variant_trait_v<double *>:
322- *reinterpret_cast <double **>(&(other.mStore )) = nullptr ;
323- return ;
324- case variant_trait_v<bool *>:
325- *reinterpret_cast <bool **>(&(other.mStore )) = nullptr ;
326- return ;
327- case variant_trait_v<std::string*>:
328- *reinterpret_cast <std::string**>(&(other.mStore )) = nullptr ;
329- default :
330- return ;
331- }
332- }
333-
334- ~Variant ()
335- {
336- // In case we allocated an array, we
337- // should delete it.
338- switch (mType ) {
339- case variant_trait_v<const char *>:
340- case variant_trait_v<int *>:
341- case variant_trait_v<float *>:
342- case variant_trait_v<double *>:
343- case variant_trait_v<bool *>:
344- case variant_trait_v<std::string*>:
345- if (reinterpret_cast <void **>(&mStore ) != nullptr ) {
346- free (*reinterpret_cast <void **>(&mStore ));
347- }
348- return ;
349- default :
350- return ;
351- }
352- }
353-
354- Variant& operator =(const Variant& other)
355- {
356- mSize = other.mSize ;
357- mType = other.mType ;
358- switch (mType ) {
359- case variant_trait_v<const char *>:
360- variant_helper<storage_t , const char *>::set (&mStore , other.get <const char *>());
361- return *this ;
362- case variant_trait_v<int *>:
363- variant_helper<storage_t , int *>::set (&mStore , other.get <int *>(), mSize );
364- return *this ;
365- case variant_trait_v<float *>:
366- variant_helper<storage_t , float *>::set (&mStore , other.get <float *>(), mSize );
367- return *this ;
368- case variant_trait_v<double *>:
369- variant_helper<storage_t , double *>::set (&mStore , other.get <double *>(), mSize );
370- return *this ;
371- case variant_trait_v<bool *>:
372- variant_helper<storage_t , bool *>::set (&mStore , other.get <bool *>(), mSize );
373- return *this ;
374- case variant_trait_v<std::string*>:
375- variant_helper<storage_t , std::string*>::set (&mStore , other.get <std::string*>(), mSize );
376- return *this ;
377- default :
378- mStore = other.mStore ;
379- return *this ;
380- }
381- }
382-
383- Variant& operator =(Variant&& other)
384- {
385- mSize = other.mSize ;
386- mType = other.mType ;
387- switch (mType ) {
388- case variant_trait_v<const char *>:
389- variant_helper<storage_t , const char *>::set (&mStore , other.get <const char *>());
390- *reinterpret_cast <char **>(&(other.mStore )) = nullptr ;
391- return *this ;
392- case variant_trait_v<int *>:
393- variant_helper<storage_t , int *>::set (&mStore , other.get <int *>(), mSize );
394- *reinterpret_cast <int **>(&(other.mStore )) = nullptr ;
395- return *this ;
396- case variant_trait_v<float *>:
397- variant_helper<storage_t , float *>::set (&mStore , other.get <float *>(), mSize );
398- *reinterpret_cast <float **>(&(other.mStore )) = nullptr ;
399- return *this ;
400- case variant_trait_v<double *>:
401- variant_helper<storage_t , double *>::set (&mStore , other.get <double *>(), mSize );
402- *reinterpret_cast <double **>(&(other.mStore )) = nullptr ;
403- return *this ;
404- case variant_trait_v<bool *>:
405- variant_helper<storage_t , bool *>::set (&mStore , other.get <bool *>(), mSize );
406- *reinterpret_cast <bool **>(&(other.mStore )) = nullptr ;
407- return *this ;
408- case variant_trait_v<std::string*>:
409- variant_helper<storage_t , std::string*>::set (&mStore , other.get <std::string*>(), mSize );
410- *reinterpret_cast <std::string**>(&(other.mStore )) = nullptr ;
411- return *this ;
412- default :
413- mStore = other.mStore ;
414- return *this ;
415- }
416- }
272+ Variant (const Variant& other);
273+ Variant (Variant&& other);
274+ ~Variant ();
275+ Variant& operator =(const Variant& other);
276+ Variant& operator =(Variant&& other);
417277
418278 template <typename T>
419279 T get () const
0 commit comments