-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67e1c4d
commit 3cbb737
Showing
6 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Boost 1.77.0: | ||
|
||
* `value_to` supports `TupleLike` types. | ||
* `object` deallocates the correct size. | ||
|
||
Boost 1.76.0: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright (c) 2021 Dmitry Arkhipov ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Official repository: https://github.com/boostorg/json | ||
// | ||
|
||
#ifndef BOOST_JSON_DETAIL_INDEX_SEQUENCE_HPP | ||
#define BOOST_JSON_DETAIL_INDEX_SEQUENCE_HPP | ||
|
||
#include <boost/json/detail/config.hpp> | ||
#ifndef BOOST_JSON_STANDALONE | ||
# include <boost/mp11/integer_sequence.hpp> | ||
#else | ||
# include <type_traits> | ||
#endif | ||
|
||
BOOST_JSON_NS_BEGIN | ||
namespace detail { | ||
|
||
#if ! defined(BOOST_JSON_STANDALONE) | ||
|
||
template <std::size_t... Is> | ||
using index_sequence = boost::mp11::index_sequence<Is...>; | ||
|
||
template <std::size_t N> | ||
using make_index_sequence = boost::mp11::make_index_sequence<N>; | ||
|
||
#else | ||
|
||
template <std::size_t... Is> | ||
using index_sequence = std::index_sequence<Is...>; | ||
|
||
template <std::size_t N> | ||
using make_index_sequence = std::make_index_sequence<N>; | ||
|
||
#endif | ||
|
||
} // detail | ||
BOOST_JSON_NS_END | ||
|
||
#endif // BOOST_JSON_DETAIL_INDEX_SEQUENCE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// | ||
// Copyright (c) 2019 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2020 Krystian Stasiowski ([email protected]) | ||
// Copyright (c) 2021 Dmitry Arkhipov ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
@@ -12,6 +13,7 @@ | |
#define BOOST_JSON_DETAIL_VALUE_TO_HPP | ||
|
||
#include <boost/json/value.hpp> | ||
#include <boost/json/detail/index_sequence.hpp> | ||
#include <boost/json/detail/value_traits.hpp> | ||
|
||
#include <type_traits> | ||
|
@@ -110,12 +112,39 @@ template<class T, typename std::enable_if< | |
T | ||
value_to_generic( | ||
const value& jv, | ||
priority_tag<2>) | ||
priority_tag<3>) | ||
{ | ||
auto& str = jv.as_string(); | ||
return T(str.data(), str.size()); | ||
} | ||
|
||
template <class T, std::size_t... Is> | ||
T | ||
make_tuple_like(const array& arr, index_sequence<Is...>) | ||
{ | ||
return T(value_to<typename std::tuple_element<Is, T>::type>(arr[Is])...); | ||
} | ||
|
||
// tuple-like types | ||
template<class T, typename std::enable_if< | ||
(std::tuple_size<remove_cvref<T>>::value > 0)>::type* = nullptr> | ||
T | ||
value_to_generic( | ||
const value& jv, | ||
priority_tag<2>) | ||
{ | ||
auto& arr = jv.as_array(); | ||
constexpr std::size_t N = std::tuple_size<remove_cvref<T>>::value; | ||
if ( N != arr.size() ) | ||
{ | ||
detail::throw_invalid_argument( | ||
"array size does not match tuple size", | ||
BOOST_JSON_SOURCE_POS); | ||
} | ||
|
||
return make_tuple_like<T>(arr, make_index_sequence<N>()); | ||
} | ||
|
||
// map like containers | ||
template<class T, typename std::enable_if< | ||
has_value_to<typename map_traits<T>::pair_value_type>::value && | ||
|
@@ -170,7 +199,7 @@ tag_invoke( | |
value const& jv) | ||
{ | ||
return value_to_generic<T>( | ||
jv, priority_tag<2>()); | ||
jv, priority_tag<3>()); | ||
} | ||
|
||
//---------------------------------------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters