27 #ifndef MLN_VALUE_INT_U_HH
28 # define MLN_VALUE_INT_U_HH
34 # include <mln/trait/all.hh>
36 # include <mln/value/ops.hh>
38 # include <mln/metal/math/pow.hh>
39 # include <mln/value/internal/value_like.hh>
40 # include <mln/value/internal/encoding.hh>
41 # include <mln/value/concept/integer.hh>
42 # include <mln/trait/value_.hh>
43 # include <mln/debug/format.hh>
45 # include <mln/value/internal/make_generic_name.hh>
54 template <
unsigned n>
struct int_u;
76 struct value_< mln::value::int_u<n> >
80 typedef typename mln::value::internal::encoding_unsigned_<n>::ret enc_;
86 card = mln_value_card_from_(n)
89 typedef trait::value::nature::integer nature;
90 typedef trait::value::kind::data kind;
91 typedef mln_value_quant_from_(card) quant;
93 static const self_ min() {
return 0; }
94 static const self_
max() {
return mlc_pow_int(2, n) - 1; }
95 static const self_ epsilon() {
return 0; }
97 typedef unsigned comp;
101 static const char* name()
104 s = mln::value::internal::make_generic_name(
"int_u", n);
120 template <
unsigned n>
122 from_to_(
const value::int_u<n>& from,
unsigned& to_);
126 template <
unsigned n>
128 from_to_(
const value::int_u<n>& from,
bool& to_);
132 template <
unsigned n>
134 from_to_(
const value::int_u<n>& from,
float& to_);
138 template <
unsigned n>
140 from_to_(
const value::int_u<n>& from,
double& to_);
155 template <
unsigned n>
160 public internal::value_like_< unsigned,
161 typename internal::encoding_unsigned_<n>::ret,
167 typedef typename internal::encoding_unsigned_<n>::ret enc_;
185 operator unsigned()
const;
199 template <>
struct int_u<0>;
200 template <>
struct int_u<1>;
211 template <
unsigned n>
212 std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i);
216 template <
unsigned n>
217 std::istream& operator>>(std::istream& istr,
int_u<n>& i);
221 # ifndef MLN_INCLUDE_ONLY
230 template <
unsigned n>
239 template <
unsigned n>
242 from_to_(
const value::int_u<n>& from,
bool& to_)
248 template <
unsigned n>
251 from_to_(
const value::int_u<n>& from,
float& to_)
253 to_ =
static_cast<float>(from);
257 template <
unsigned n>
260 from_to_(
const value::int_u<n>& from,
double& to_)
262 to_ =
static_cast<double>(from);
274 template <
unsigned n>
280 template <
unsigned n>
284 mln_precondition(i >= 0);
285 mln_precondition(
unsigned(i) <= mln_max(enc_));
286 this->v_ =
static_cast<enc_
>(i);
289 template <
unsigned n>
296 template <
unsigned n>
305 template <
unsigned n>
312 template <
unsigned n>
321 template <
unsigned n>
328 template <
unsigned n>
333 return - int(this->v_);
336 template <
unsigned n>
341 mln_precondition(i >= 0);
342 mln_precondition(
unsigned(i) <= mln_max(enc_));
343 this->v_ =
static_cast<enc_
>(i);
347 template <
unsigned n>
355 template <
unsigned n>
357 std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i)
363 template <
unsigned n>
365 std::istream& operator>>(std::istream& istr,
int_u<n>& i)
367 return istr >> i.handle_();
372 # endif // ! MLN_INCLUDE_ONLY
377 #endif // ! MLN_VALUE_INT_U_HH