44#ifndef TAOCPP_JSON_INCLUDE_BINARY_HPP
55#define TAOCPP_JSON_INCLUDE_BINARY_HPP
66
7- #include < initializer_list>
87#include < vector>
98
109#include " byte.hpp"
11- #include " internal/integer_sequence.hpp"
1210
1311namespace tao
1412{
@@ -21,19 +19,34 @@ namespace tao
2119 return ( c < ' A' ) ? ( c - ' 0' ) : ( ( c < ' a' ) ? ( c - ' A' + 10 ) : ( c - ' a' + 10 ) );
2220 }
2321
24- template < typename T, typename V, char ... Cs, std::size_t ... Is >
25- constexpr T unhex ( index_sequence< Is... >, std::initializer_list< char > a )
22+ template < typename V, V... >
23+ struct vlist ;
24+
25+ template < typename T, typename L, char ... Cs >
26+ struct unhex_helper ;
27+
28+ template < typename T, typename V, V... Vs >
29+ struct unhex_helper < T, vlist< V, Vs... > >
2630 {
27- return T{ V ( ( a.begin ()[ 2 * Is ] << 4 ) + a.begin ()[ 2 * Is + 1 ] )... };
28- }
31+ static constexpr T unhex ()
32+ {
33+ return T{ Vs... };
34+ }
35+ };
36+
37+ template < typename T, typename V, char C0, char C1, char ... Cs, V... Vs >
38+ struct unhex_helper < T, vlist< V, Vs... >, C0, C1, Cs... >
39+ : unhex_helper< T, vlist< V, Vs..., V( ( C0 << 4 ) + C1 ) >, Cs... >
40+ {
41+ };
2942
3043 template < typename T, typename V, char C0, char C1, char ... Cs >
3144 constexpr T unhex ()
3245 {
3346 static_assert ( C0 == ' 0' , " not a hex literal" );
3447 static_assert ( C1 == ' x' || C1 == ' X' , " not a hex literal" );
3548 static_assert ( sizeof ...( Cs ) % 2 == 0 , " invalid number of hexadecimal digits" );
36- return unhex < T, V, Cs... >( make_index_sequence< sizeof ...( Cs ) / 2 >(), { unhex_char ( Cs )... } );
49+ return unhex_helper < T, vlist< V >, unhex_char ( Cs )... >:: unhex ( );
3750 }
3851
3952 template < typename T, char ... Cs >
0 commit comments