14 #include <type_traits>
17 #include <nlohmann/detail/macro_scope.hpp>
70 : is(i), sb(*i.rdbuf())
73 std::char_traits<char>::int_type c;
82 else if (c != std::char_traits<char>::eof())
88 else if (c != std::char_traits<char>::eof())
94 else if (c != std::char_traits<char>::eof())
128 : cursor(b), limit(b + l), start(b)
131 if (l >= 3 and b[0] ==
'\xEF' and b[1] ==
'\xBB' and b[2] ==
'\xBF')
143 if (JSON_LIKELY(cursor < limit))
145 return std::char_traits<char>::to_int_type(*(cursor++));
148 return std::char_traits<char>::eof();
153 if (JSON_LIKELY(cursor > start))
182 template<
typename CharT,
183 typename std::enable_if<
184 std::is_pointer<CharT>::value and
185 std::is_integral<typename std::remove_pointer<CharT>::type>::value and
186 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
189 : ia(std::make_shared<input_buffer_adapter>(reinterpret_cast<const char*>(b), l)) {}
194 template<
typename CharT,
195 typename std::enable_if<
196 std::is_pointer<CharT>::value and
197 std::is_integral<typename std::remove_pointer<CharT>::type>::value and
198 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
202 std::strlen(reinterpret_cast<const char*>(b))) {}
205 template<
class IteratorType,
206 typename std::enable_if<
207 std::is_same<typename std::iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
213 assert(std::accumulate(
214 first, last, std::pair<bool, int>(
true, 0),
215 [&first](std::pair<bool, int> res, decltype(*first) val)
217 res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
223 sizeof(
typename std::iterator_traits<IteratorType>::value_type) == 1,
224 "each element in the iterator range must have the size of 1 byte");
226 const auto len = static_cast<size_t>(std::distance(first, last));
227 if (JSON_LIKELY(len > 0))
230 ia = std::make_shared<input_buffer_adapter>(reinterpret_cast<const char*>(&(*first)), len);
235 ia = std::make_shared<input_buffer_adapter>(
nullptr, len);
240 template<
class T, std::
size_t N>
245 template<
class ContiguousContainer,
typename
246 std::enable_if<not std::is_pointer<ContiguousContainer>::value and
247 std::is_base_of<std::random_access_iterator_tag, typename std::iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value,