Skip to content

Commit 15fde53

Browse files
committed
variant, epoch traits
1 parent 1ed9abe commit 15fde53

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

include/jsoncons/reflect/json_conv_traits.hpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,21 +1438,21 @@ namespace variant_detail
14381438
}
14391439
}
14401440

1441-
template<int N,typename Json,typename Variant,typename ... Args>
1441+
template<int N,typename Json,typename Variant,Alloc,TempAlloc,VariantTypes,typename ... Args>
14421442
typename std::enable_if<N == std::variant_size_v<Variant>, conversion_result<Variant>>::type
1443-
as_variant(const Json& /*j*/)
1443+
as_variant(const allocator_set<Alloc,TempAlloc>&, const Json& /*j*/)
14441444
{
14451445
return conversion_result<Variant>(jsoncons::unexpect, conv_errc::not_variant);
14461446
}
14471447

1448-
template<std::size_t N,typename Json,typename Variant,typename T,typename ... U>
1448+
template<std::size_t N,typename Json,typename Variant,Alloc,TempAlloc,VariantTypes,typename T,typename ... U>
14491449
typename std::enable_if<N < std::variant_size_v<Variant>, conversion_result<Variant>>::type
1450-
as_variant(const Json& j)
1450+
as_variant(const allocator_set<Alloc,TempAlloc>& aset, const Json& j)
14511451
{
14521452
using result_type = conversion_result<Variant>;
14531453
if (j.template is<T>())
14541454
{
1455-
auto res = j.template try_as<T>();
1455+
auto res = j.template try_as<T>(aset);
14561456
if (JSONCONS_UNLIKELY(!res))
14571457
{
14581458
return result_type(jsoncons::unexpect, conv_errc::not_variant);
@@ -1494,9 +1494,9 @@ namespace variant_detail
14941494
}
14951495

14961496
template <typename Alloc, typename TempAlloc>
1497-
static result_type try_as(const allocator_set<Alloc,TempAlloc>&, const Json& j)
1497+
static result_type try_as(const allocator_set<Alloc,TempAlloc>& aset, const Json& j)
14981498
{
1499-
return result_type(variant_detail::as_variant<0,Json,variant_type, VariantTypes...>(j));
1499+
return result_type(variant_detail::as_variant<0,Json,variant_type,Alloc,TempAlloc,VariantTypes...>(aset, j));
15001500
}
15011501

15021502
template <typename Alloc>
@@ -1528,21 +1528,21 @@ namespace variant_detail
15281528
}
15291529

15301530
template <typename Alloc, typename TempAlloc>
1531-
static result_type try_as(const allocator_set<Alloc,TempAlloc>&, const Json& j)
1531+
static result_type try_as(const allocator_set<Alloc,TempAlloc>& aset, const Json& j)
15321532
{
1533-
return from_json_(j);
1533+
return from_json_(aset, j);
15341534
}
15351535

15361536
template <typename Alloc>
1537-
static Json to_json(const duration_type& val, const Alloc&)
1537+
static Json to_json(const duration_type& val, const Alloc& alloc)
15381538
{
1539-
return to_json_(val);
1539+
return to_json_(val, alloc);
15401540
}
15411541

1542-
template <typename PeriodT=Period>
1542+
template <typename Alloc, typename TempAlloc, typename PeriodT=Period>
15431543
static
15441544
typename std::enable_if<std::is_same<PeriodT,std::ratio<1>>::value, result_type>::type
1545-
from_json_(const Json& j)
1545+
from_json_(const allocator_set<Alloc,TempAlloc>& aset, const Json& j)
15461546
{
15471547
if (j.is_int64() || j.is_uint64() || j.is_double())
15481548
{
@@ -1598,7 +1598,7 @@ namespace variant_detail
15981598
}
15991599
default:
16001600
{
1601-
auto res = j.template try_as<Rep>();
1601+
auto res = j.template try_as<Rep>(aset);
16021602
if (!res)
16031603
{
16041604
return result_type(unexpect, conv_errc::not_epoch);
@@ -1613,10 +1613,10 @@ namespace variant_detail
16131613
}
16141614
}
16151615

1616-
template <typename PeriodT=Period>
1616+
template <typename Alloc, typename TempAlloc, typename PeriodT=Period>
16171617
static
16181618
typename std::enable_if<std::is_same<PeriodT,std::milli>::value, result_type>::type
1619-
from_json_(const Json& j)
1619+
from_json_(const allocator_set<Alloc,TempAlloc>& aset, const Json& j)
16201620
{
16211621
if (j.is_int64() || j.is_uint64())
16221622
{
@@ -1698,7 +1698,7 @@ namespace variant_detail
16981698
}
16991699
default:
17001700
{
1701-
auto res = j.template try_as<Rep>();
1701+
auto res = j.template try_as<Rep>(aset);
17021702
if (!res)
17031703
{
17041704
return result_type(unexpect, conv_errc::not_epoch);
@@ -1713,10 +1713,10 @@ namespace variant_detail
17131713
}
17141714
}
17151715

1716-
template <typename PeriodT=Period>
1716+
template <typename Alloc, typename TempAlloc, typename PeriodT=Period>
17171717
static
17181718
typename std::enable_if<std::is_same<PeriodT,std::nano>::value, result_type>::type
1719-
from_json_(const Json& j)
1719+
from_json_(const allocator_set<Alloc,TempAlloc>& aset, const Json& j)
17201720
{
17211721
if (j.is_int64() || j.is_uint64() || j.is_double())
17221722
{
@@ -1750,7 +1750,7 @@ namespace variant_detail
17501750
}
17511751
else if (j.is_string())
17521752
{
1753-
auto res = j.template try_as<Rep>();
1753+
auto res = j.template try_as<Rep>(aset);
17541754
if (!res)
17551755
{
17561756
return result_type(unexpect, conv_errc::not_epoch);
@@ -1773,28 +1773,28 @@ namespace variant_detail
17731773
}
17741774
}
17751775

1776-
template <typename PeriodT=Period>
1776+
template <typename Alloc,typename PeriodT=Period>
17771777
static
17781778
typename std::enable_if<std::is_same<PeriodT,std::ratio<1>>::value,Json>::type
1779-
to_json_(const duration_type& val)
1779+
to_json_(const duration_type& val, const Alloc& alloc)
17801780
{
1781-
return Json(val.count(), semantic_tag::epoch_second);
1781+
return make_json_using_allocator<Json>(alloc, val.count(), semantic_tag::epoch_second);
17821782
}
17831783

1784-
template <typename PeriodT=Period>
1784+
template <typename Alloc,typename PeriodT=Period>
17851785
static
17861786
typename std::enable_if<std::is_same<PeriodT,std::milli>::value,Json>::type
1787-
to_json_(const duration_type& val)
1787+
to_json_(const duration_type& val, const Alloc& alloc)
17881788
{
1789-
return Json(val.count(), semantic_tag::epoch_milli);
1789+
return make_json_using_allocator<Json>(alloc, val.count(), semantic_tag::epoch_milli);
17901790
}
17911791

1792-
template <typename PeriodT=Period>
1792+
template <typename Alloc,typename PeriodT=Period>
17931793
static
17941794
typename std::enable_if<std::is_same<PeriodT,std::nano>::value,Json>::type
1795-
to_json_(const duration_type& val)
1795+
to_json_(const duration_type& val, const Alloc& alloc)
17961796
{
1797-
return Json(val.count(), semantic_tag::epoch_nano);
1797+
return make_json_using_allocator<Json>(alloc, val.count(), semantic_tag::epoch_nano);
17981798
}
17991799
};
18001800

0 commit comments

Comments
 (0)