32 #ifndef VSMC_INTERNAL_BASIC_HPP 33 #define VSMC_INTERNAL_BASIC_HPP 56 #include <initializer_list> 72 #include <type_traits> 83 inline bool is_equal(
const T &a,
const T &b, std::true_type)
85 return !(a < b || a > b);
89 inline bool is_equal(
const T &a,
const T &b, std::false_type)
97 return is_equal(a, b, std::is_floating_point<T>());
100 template <
typename T>
103 return is_equal(a, static_cast<T>(0));
106 template <
typename T>
109 return is_equal(a, static_cast<T>(1));
112 template <
typename T>
118 template <
typename T>
124 template <
typename T>
130 template <
typename T>
133 return ptr ==
nullptr;
136 template <
typename T>
142 template <
typename T>
148 template <
unsigned long long U,
149 int N = std::numeric_limits<unsigned long long>::digits - 1>
152 static constexpr
unsigned long long M = 1ULL << N;
158 template <
unsigned long long U>
172 template <
typename UIntType, UIntType U>
173 class Log2 :
public Log2L<U, std::numeric_limits<UIntType>::digits - 1>
177 template <
typename T>
178 class BufferSize :
public std::integral_constant<std::size_t, 8192 / sizeof(T)>
182 template <std::size_t,
typename CharT,
typename Traits,
typename T,
185 const std::array<T, N> &, std::false_type)
189 template <std::size_t,
typename CharT,
typename Traits,
typename T,
192 const std::array<T, N> &, std::true_type)
197 template <std::size_t,
typename CharT,
typename Traits,
typename T,
200 const std::array<T, N> &, std::false_type)
204 template <std::size_t K,
typename CharT,
typename Traits,
typename T,
207 const std::array<T, N> &ary, std::true_type)
209 os << std::get<K>(ary);
210 ostream_ary_space<K>(os, ary, std::integral_constant<bool, K + 1 != N>());
211 ostream_ary<K + 1>(os, ary, std::integral_constant<bool, K + 1 < N>());
214 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
215 inline std::basic_ostream<CharT, Traits> &
ostream(
216 std::basic_ostream<CharT, Traits> &os,
const std::array<T, N> &ary)
221 ostream_ary<0>(os, ary, std::integral_constant<bool, 0 < N>());
226 template <std::size_t,
typename CharT,
typename Traits,
typename T,
229 std::basic_istream<CharT, Traits> &, std::array<T, N> &, std::false_type)
233 template <std::size_t K,
typename CharT,
typename Traits,
typename T,
236 std::array<T, N> &ary, std::true_type)
238 is >> std::ws >> std::get<K>(ary);
239 istream_ary<K + 1>(is, ary, std::integral_constant<bool, K + 1 < N>());
242 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
243 inline std::basic_istream<CharT, Traits> &
istream(
244 std::basic_istream<CharT, Traits> &is, std::array<T, N> &ary)
249 std::array<T, N> tmp;
250 istream_ary<0>(is, tmp, std::integral_constant<bool, 0 < N>());
252 ary = std::move(tmp);
257 template <
typename CharT,
typename Traits,
typename T,
typename Alloc>
258 inline std::basic_ostream<CharT, Traits> &
ostream(
259 std::basic_ostream<CharT, Traits> &os,
const std::vector<T, Alloc> &vec)
268 for (
const auto &v : vec)
274 template <
typename CharT,
typename Traits,
typename T,
typename Alloc>
275 inline std::basic_istream<CharT, Traits> &
istream(
276 std::basic_istream<CharT, Traits> &is, std::vector<T, Alloc> &vec)
286 std::vector<T, Alloc> tmp(n);
287 for (std::size_t i = 0; i != n; ++i)
288 is >> std::ws >> tmp[i];
290 vec = std::move(tmp);
295 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
297 std::basic_ostream<CharT, Traits> &os,
const std::array<T, N> &ary)
302 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
304 std::basic_istream<CharT, Traits> &is, std::array<T, N> &ary)
309 template <
typename CharT,
typename Traits,
typename T,
typename Alloc>
311 std::basic_ostream<CharT, Traits> &os,
const std::vector<T, Alloc> &vec)
316 template <
typename CharT,
typename Traits,
typename T,
typename Alloc>
318 std::basic_istream<CharT, Traits> &is, std::vector<T, Alloc> &vec)
325 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
327 std::basic_ostream<CharT, Traits> &os,
const std::array<T, N> &ary)
332 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
334 std::basic_istream<CharT, Traits> &is, std::array<T, N> &ary)
339 template <
typename CharT,
typename Traits,
typename T,
typename Alloc>
341 std::basic_ostream<CharT, Traits> &os,
const std::vector<T, Alloc> &vec)
346 template <
typename CharT,
typename Traits,
typename T,
typename Alloc>
348 std::basic_istream<CharT, Traits> &is, std::vector<T, Alloc> &vec)
355 #endif // VSMC_INTERNAL_BASIC_HPP
std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, std::array< T, N > &ary)
void istream_ary(std::basic_istream< CharT, Traits > &, std::array< T, N > &, std::false_type)
std::basic_ostream< CharT, Traits > & ostream(std::basic_ostream< CharT, Traits > &os, const std::array< T, N > &ary)
void ostream_ary(std::basic_ostream< CharT, Traits > &, const std::array< T, N > &, std::false_type)
void ostream_ary_space(std::basic_ostream< CharT, Traits > &, const std::array< T, N > &, std::false_type)
bool is_equal(const T &a, const T &b, std::true_type)
static constexpr int value
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const std::array< T, N > &ary)
bool is_negative(const T &, std::true_type)
bool is_nullptr(T ptr, std::true_type)
std::basic_istream< CharT, Traits > & istream(std::basic_istream< CharT, Traits > &is, std::array< T, N > &ary)