32 #ifndef VSMC_INTERNAL_COMMON_HPP 33 #define VSMC_INTERNAL_COMMON_HPP 61 #include <initializer_list> 78 #include <type_traits> 88 template <
typename UIntType>
89 inline std::string
itos(UIntType i, std::true_type)
92 return std::string(
"0");
97 str[n++] =
'0' + i % 10;
100 std::reverse(str, str + n);
102 return std::string(str);
105 template <
typename IntType>
106 inline std::string
itos(IntType i, std::false_type)
108 using uint_type =
typename std::make_unsigned<IntType>::type;
111 return "-" +
itos(static_cast<uint_type>(-i), std::true_type());
113 return itos(static_cast<uint_type>(i), std::true_type());
116 template <
typename IntType>
117 inline std::string
itos(IntType i)
119 return itos(i, std::is_unsigned<IntType>());
124 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
126 std::basic_ostream<CharT, Traits> &os,
const std::array<T, N> &ary)
131 for (std::size_t i = 0; i < N - 1; ++i)
138 template <
typename CharT,
typename Traits,
typename T, std::
size_t N>
140 std::basic_istream<CharT, Traits> &is, std::array<T, N> &ary)
145 std::array<T, N> ary_tmp;
146 for (std::size_t i = 0; i != N; ++i)
147 is >> std::ws >> ary_tmp[i];
150 ary = std::move(ary_tmp);
157 #endif // VSMC_INTERNAL_COMMON_HPP
std::string itos(UIntType i, std::true_type)
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Sampler< T > &sampler)
std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, std::array< T, N > &ary)