@@ -335,6 +335,17 @@ namespace bencode {
335
335
template <typename T>
336
336
inline constexpr bool is_view_v = is_view<T>::value;
337
337
338
+ template <typename , typename = std::void_t <>>
339
+ struct is_iterable : std::false_type {};
340
+
341
+ template <typename T>
342
+ struct is_iterable <T, std::void_t <
343
+ decltype (std::begin(std::declval<T&>()), std::end(std::declval<T&>()))
344
+ >> : std::true_type {};
345
+
346
+ template <typename T>
347
+ inline constexpr bool is_iterable_v = is_iterable<T>::value;
348
+
338
349
template <typename Integer>
339
350
inline void check_overflow (Integer value, Integer digit) {
340
351
using limits = std::numeric_limits<Integer>;
@@ -607,9 +618,21 @@ namespace bencode {
607
618
return detail::do_decode<Data>(b, end, true );
608
619
}
609
620
621
+ template <typename Data, typename String,
622
+ std::enable_if_t <detail::is_iterable_v<String> &&
623
+ !std::is_array_v<String>, bool > = true >
624
+ inline Data basic_decode (const String &s) {
625
+ return basic_decode<Data>(std::begin (s), std::end (s));
626
+ }
627
+
628
+ template <typename Data>
629
+ inline Data basic_decode (const char *s) {
630
+ return basic_decode<Data>(s, s + std::strlen (s));
631
+ }
632
+
610
633
template <typename Data>
611
- inline Data basic_decode (const string_view &s ) {
612
- return basic_decode<Data>(s. begin () , s. end () );
634
+ inline Data basic_decode (const char *s, std:: size_t length ) {
635
+ return basic_decode<Data>(s, s + length );
613
636
}
614
637
615
638
template <typename Data>
@@ -622,6 +645,16 @@ namespace bencode {
622
645
return detail::do_decode<Data>(begin, end, false );
623
646
}
624
647
648
+ template <typename Data>
649
+ inline Data basic_decode_some (const char *&s) {
650
+ return basic_decode_some<Data>(s, s + std::strlen (s));
651
+ }
652
+
653
+ template <typename Data>
654
+ inline Data basic_decode_some (const char *&s, std::size_t length) {
655
+ return basic_decode_some<Data>(s, s + length);
656
+ }
657
+
625
658
template <typename Data>
626
659
inline Data basic_decode_some (std::istream &s, eof_behavior e = check_eof) {
627
660
return detail::do_decode<Data>(s, e, false );
0 commit comments